PROXYC - EDITORIAL

https://www.codechef.com/viewsolution/29305865

Can somebody find a test case for which this solution is wrong
I have tried all the test cases provided in this discussion thread.

Consider the testcase:

1
13
PAPAPAPPAPAAA

2 Likes

Thank you
found the error

1 Like

All within 3 minutes :slight_smile:

2 Likes

please help me where i am wrong :shushing_face:
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,i,p=0,prox=0,np=0;
string s;
double per;
cin>>n;
cin>>s;
if(n==1)
{
if(s[0]==β€˜A’)
cout<<1<<endl;
else
cout<<0<<endl;
}
else if(n==2)
{
if((s[0]==β€˜A’) && (s[1]==β€˜A’))
cout<<2<<endl;
else if(((s[0]==β€˜A’) && (s[1]==β€˜P’))|| ((s[0]==β€˜P’) && (s[1]==β€˜A’)))
cout<<1<<endl;
else
cout<<0<<endl;
}
else
{
for(i=0;i<n;i++)
{
if(s[i]==β€˜P’)
p++;
}
per=(double)p/n;
if(per>=0.75)
cout<<0<<endl;
else
{
for(i=0;i<n;i++)
{
if(i==0)
{
if((s[i]==β€˜A’) && ((s[i+1]==β€˜P’) || (s[i+1]==β€˜P’)))
{
p++;
np++;
s[i]=β€˜P’;
}
}
else if(i==1)
{
if((s[i]==β€˜A’) && ((s[i+1]==β€˜P’) || (s[i+2]==β€˜P’) ||(s[i-1]==β€˜P’)))
{
p++;
np++;
s[i]=β€˜P’;
}
}
else
{
if((s[i]==β€˜A’) && ((s[i+1]==β€˜P’) || (s[i+2]==β€˜P’) ||(s[i-1]==β€˜P’) || (s[i-2]==β€˜P’)))
{
p++;
np++;
s[i]=β€˜P’;
}
}
per=(double)p/n;
if(per>=0.75)
break;
}
//cout<<β€œper=”<<per<<β€œnp=”<<np<<endl;
if(per>=0.75)
cout<<np<<endl;
else
cout<<-1<<endl;
}
}
}
return 0;
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

1 Like

here is link
https://www.codechef.com/viewsolution/36147739

1 Like

Thanks! The following test input causes an out-of-bounds access in your solution:

1
5
AAAAA
2 Likes

It gives -1 as output

That is correct output,i think.

For this input i get -1 as output that is correct

https://www.codechef.com/viewsolution/37764805

Please help me out with the code.Dummy testcases have passed.If anybody can find me some test cases which are outputting wrong from my code.
Thanks in advance.

Consider the test input:

1
4
PAAP
2 Likes

Thanks for replying ,i understood where i did mistake.

1 Like

https://www.codechef.com/viewsolution/39844684
can anyone help me with this? where am i getting this wrong .

https://www.codechef.com/viewsolution/46630201

I have tried multiple test-cases with all correct answers. I don’t know where I am getting wrong. It will be very helpful, if someone help me in finding the bug.

Consider the test input:

1
7
APAPAPP

Thank you for the correction!
But, I am still getting a SIGSEGV error (Runtime error). I tried to check for any divide by 0 error , but there is no such division. Also, memory usage is not too much. I don’t know why still I am getting such error :frowning: .

1 Like

Please link to your updated code.

https://www.codechef.com/viewsolution/46656054