Why i am getting WA (PROXYC)


code is:

#include <stdio.h>
int main(void)
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int d,i,count=0,preq=0,ppos=0;
        double a;
        scanf("%d",&d);
        //fflush(stdin);
        char str[d+1];
        scanf("%s",str);
        //fflush(stdin);
        for(i=0;i<=d-1;i++)
        {
            if(str[i]=='P')
            count++;
        }
        //printf("count of p=%d\n",count);
        //if(count/(d*1.00)>=0.75)
        //{
            //printf("0\n");
        //}
        if(count/(d*1.00)<0.75)
        {
           a=d*(0.75-count/(d*1.00));
           preq=ceil(a);
        }
        //printf("preq=%d\n",preq);
        
for(i=2;i<=d-3;i++)
        {
            if(str[i]=='A')
            {
                
                if(str[i-1]=='P'||str[i-2]=='P')
                {
                   if(str[i+1]=='P'||str[i+2]=='P')
                   ppos++;
                }
                
            }
        }
       // printf("ppos=%d\n",ppos);
        if(preq<=ppos)
        printf("%d\n",preq);
        if(preq>ppos)
        printf("-1\n");
        
    }
    return 0;
}

Here’s a random testcase where your solution fails:

1
356
AAAAPAPPPAPAPAPAPAPPPPPAPPPPPPPPPPPPAPPPPAPAAPPPAPPAAAPAPAPAPAAAAAPPAAAPPPPAPAPPPPPPPPAPAAPAPPPAPPPPPPPAAPPPAPAPAPPPPAAAPPPPPAPAPPPPPPAPPPPPAPPAPPPAPAAPPPPAAPAPPAPPAAPPPAAAAAPPPPPPAPPPAPPPAPPPPAPAPPAPPAAPAPPPPPAPPAAPPPPPPPAAAPAPPPAPPPAPAAAPAAAAAPAAPAPPPAPAPAPAPAPPAPAPPAPPAAAPPAPPAPPPAPPAPAPPAPPPPPAAPPPPPPPPPPPPAPPPAAPPAAAPPPPPPPPPAPPPPAPPPPPPPPAAPPPAPPPP

(the answer should be 34).

2 Likes