# PROXYC - EDITORIAL

Hello,

i executed my code with two different ways to calculate the minimum of days he has to be attendant.

timeDuration = All Lessons he should have attended.

1. `````` int x = (int) Math.ceil(((timeDuration/100.0)*75));
``````
2. ``````        int y =    (int) Math.ceil(timeDuration*0.75);
``````

With way 1 i got a wrong answer, way 2 worked. i tested both ways with some numbers and 1 and 2 output allways the same.

Can you give me an example where 1 is wrong ?

Why am I getting Wrong Answer
#include <bits/stdc++.h>
using namespace std;

``````int main()
{
int t,n,present_count,count,flag,i;
float attendence;
string s;
cin >> t;
while(t--)
{
cin >> n;
cin >> s;

present_count = 0,count = 0,flag = 0;

for(i=0; i<n; i++)
{
if(s[i] == 'P')
present_count++;
}
attendence = (float)present_count/n;
if(attendence >= 0.75)
{
cout << 0 << "\n";
continue;
}
else
{
for(i=2; i<n-2; i++)
{
if(s[i] == 'A')
{
if( (s[i-1] == 'P' || s[i-2] == 'P') && (s[i+1] == 'P' || s[i+2] == 'P') )
{
s[i] = 'P';
count++; present_count++;
attendence = (float)present_count/n;
if(attendence >= 0.75)
{
flag = 1;
break;
}
}
}
}
if(flag == 0)
cout << -1 << "\n";
else
cout << count << "\n";
}
}
}``````

What is is wrong in this code?
#include
#include<string.h>
using namespace std;
int main()
{
int D,T,i,j,P,change=0;
char S[1000];
cin>>T;
if(T>2000)
{
exit(0);
}
for(i=0;i<T;i++)
{
cin>>D>>S;
if(D>1000)
{
exit(0);
}
for(j=0;j<D;j++)
{
if(S[j]!=βAβ&&S[j]!=βPβ)
{
exit(0);
}
}
for(j=0;j<D;j++)
{
if(S[j]==βPβ)
{
P++;
}
}

``````	if((P*100)/D>=75)
{
cout<<0;
}
else
{
for(j=2;j<D-2;j++)
{
if(S[j]=='A')
{

if(S[j-2]=='P'||S[j-1]=='P'||S[j+2]=='P'||S[j+1]=='P')
{
change++;
P=P+1;
if(((P*100)/D)>=75)
{
cout<<change;
break;
}
}
}
}

}
}
``````

}

for x in range(int(input())):
d = int(input())
s = input()
a = s.count(βPβ)
b = 0
if a/d >= 0.75:
print(-1)
else:
for y in range(2,d-2):
if s[y] == βAβ and (s[y-1] == βPβ or s[y-2] == βPβ) and (s[y+1] == βPβ or s[y+2] == βPβ):
a += 1
b += 1
if a/d >= 0.75:
print(b)
break
else:
print(-1)

Whatβs Wrong With My Codeβ¦

Whatβs wrong with this code?
https://www.codechef.com/viewsolution/29123229

You have an out-of-bounds access here:

``````        s[d]='\0';
``````
2 Likes

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

2 Likes

#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!

1 Like

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.
``````1