Please help me , Debug this code (Chef and Proxy) (PROXYC) , Please , I'm new here and this was my first contest , after passing almost all the manually created test cases , corner cases , I think I'm right , I don't know why I'm getting WA :(

/*I have submitted almost 20 times , still I’m not getting , I’m little confident that my answer is //correct but I don’t know on which test case my solution is wrong , please help me, please ,I’m /*new here

#include <iostream>

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
    int t,i,count,counter;
    double curr_percent,len;
    string a;
    cin>>len;
    cin>>a;

i=0; 
count=0; 
counter=0;

while(i < a.length())
{

if (a[i]=='P')
{count++;}
i++;

}

curr_percent=(double)count/len;

if(curr_percent>=0.75)
cout<<"0"<<endl;

else
{

i=2;
while(i< a.length())
{

if(a[i]=='A')
{
if((a[i-1]=='P'||a[i-2]=='P')  && (a[i+1]=='P'||a[i+2]=='P'))
{

counter++;
count=count+1;
curr_percent=(double)count/len;
if(curr_percent>=0.75)
break;

}
}
i++;
}
if (counter>0 && curr_percent>=0.75)
cout<<counter<<endl;
else
cout<<"-1"<<endl;


}
}

return 0;

}

may be it could be while(i<a.length()-2) might do the trick. As proxy cannot be marked on first 2 and last 2 days :slight_smile:

I have also done what you are saying but still not getting the answer ,Could you please find few test cases where my answer could be wrong ? Why I feel like my solution is right on every test cases

https://www.codechef.com/viewsolution/24854543
check it bro, you will find

1 Like

Thank you so much bro .

can anyone check my solution! It’s giving me WA and idk why!

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

@anon4198588
Test case : 12
PPAPPPPPPPPP
Ur code gives 1. Required answer 0. If A is present at position 2, proxy becomes at least 1, even when not required.

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

I too am passing all testcases I have created.I have checked other correct solutions,but I still cannot find where am I going wrong.Can someone please suggest a testcase where my code would not work.

import sys

T = int(input())  # No. of testcases

def proxydays(s, S):
    """
    Input: The attendance string and its size
    Output: Required no. of days to get 75% attendance
    """
    act = float(S.count('P'))/float(s)
    if (act < 0.75):
        req = int((0.75-act)*s) + 1
        return(req)
    else:
        return(0)


def proxymaker(s, A):
    """
    Input: Att. string, its size, required no. of days
    Output: No. of possible proxies
    """
    p_days = 0
    for i in range(2, s-2):
        con1 = False
        con2 = False
        con3 = False
        if (A[i] == 'A'):
            con1 = True
        if (A[i-1] == 'P') or (A[i-2] == 'P'):
            con2 = True
        if (A[i+1] == 'P') or (A[i+2] == 'P'):
            con3 = True
        if (con1 and (con2 and con3)):
            p_days += 1

    return(p_days)


while T:
    s = int(input())
    S = input()

    req_days = proxydays(s, S)
    proxy_days = proxymaker(s, S)

    if (req_days > 0):
        if (proxy_days >= req_days):
            print(req_days)
        else:
            print("-1")
    else:
        print("0")

    T -= 1

It turns out that there were certain testcases I was not passing where attendance = 0.75
So instead of doing

   if (act < 0.75):
            req = int((0.75-act)*s) + 1
            return(req)

I did

if (act < 0.75):
        req = math.ceil((0.75-act) * s)
        return(req)

But I am still getting wrong answer when I submit.Can someone please explain where am I going wrong?

Oh! i forgot to check for the cases where there is no need of proxy for 4 days or more! Thank you!