fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5. int main()
  6. {
  7. ll t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. ll lec;
  12. cin>>lec;
  13. string s;
  14. cin>>s;
  15. lec=s.size();
  16. ll att=0;
  17. ll req;
  18. for(ll i=0;i<lec;i++)
  19. {
  20. if(s[i]=='P')
  21. {
  22. att++;
  23. }
  24. }
  25. if((att*100)/lec<75)
  26. {
  27. ll prox=0;
  28. req=((75*lec)/100-att)+1;
  29. //cout<<req<<endl;
  30. for(int i=2;i<=lec-3;i++)
  31. {
  32. bool y = s[i-1]=='P'||s[i-2]=='P';
  33. bool z = s[i+1]=='P'||s[i+2]=='P';
  34. bool res=y&&z;
  35. if(res&&prox<req)
  36. {
  37. prox++;
  38. }
  39.  
  40. }
  41. if(prox>=req)
  42. {
  43. cout<<prox<<endl;
  44. }
  45. else
  46. {
  47. cout<<"-1"<<endl;
  48. }
  49. }
  50. else
  51. {
  52. cout<<"0"<<endl;
  53. }
  54.  
  55. }
  56. }
  57.  
Success #stdin #stdout 0s 15240KB
stdin
1
9
AAAAAAAAA
stdout
-1