Jun 16, 2019 at 8:21pm UTC
I
Last edited on Jun 17, 2019 at 11:46am UTC
Jun 16, 2019 at 9:12pm UTC
only 1 condition exists...
for(ll i=0;i<n;i++)
{
if(s[i]=='P')
{
count++;
}
}
l
ll c1=0;
for(ll 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'))
{
c1++;
}
}
}
calcualte 75% of n if(75% of n<=count) then print count
else calculate how much your need to obtain 75% (need-count)
if(need-count<=c1) then print need-count else print -1
Jun 17, 2019 at 2:36am UTC
Last edited on Jun 17, 2019 at 6:54am UTC
Jun 17, 2019 at 6:00am UTC
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll tc,length,count,itr,can;
string str;
cin >> tc;
while(tc--)
{
cin>>length;
cin>>str;
count =0;
itr=0;
can =0;
for(itr=0;itr<length;itr++){
if(str[itr] == 'P'){
count++;
}
}
for(itr=2;itr < length-2;itr++){
if(str[itr] == 'A'){
if((str[itr-2] == 'P'|| str[itr-1] =='P') && (str[itr+1] =='P' || str[itr+2]== 'P')){
can++;
}
}
}
//itr++;
// }
if((n*75)%100==0)
{needed=(n*(0.75));}
else
{needed=((n*(0.75))+1);}
if(can >= (needed -count))
cout<<needed-count;
else if(( needed-count) <0)
{
cout << "0";
}
else cout <<"-1";
cout<<"\n";
}
}
check this one