Skip to content

Instantly share code, notes, and snippets.

@vaibhavgeek
Last active June 10, 2019 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaibhavgeek/a7c797692f3069b554dbaacd549aa61e to your computer and use it in GitHub Desktop.
Save vaibhavgeek/a7c797692f3069b554dbaacd549aa61e to your computer and use it in GitHub Desktop.
Why is this not working?
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
if(n <= 4) { cout<<-1<<endl; break; }
char ch;
int count=0;
int avail[n] = {0};
for(int i=0;i<n;i++){
cin>>ch;
if(ch == 'P') {
count++;
avail[i] = 1;
}
}
double att;
att = (count * (1.00)) / n;
if(att > 0.75) {cout<<0<<endl; break; }
for(int i=2;i<(n-2);i++)
{
if(avail[i] == 0){
if(avail[i-1] == 1 || avail[i-2] == 1)
{
if(avail[i+1] == 1 || avail[i+2] == 1) avail[i] = 2;
}
}
}
int j = 0;
for(int i=2;i<(n-2);i++)
{
if(avail[i] == 2 && att < 0.75)
{
att = att + (1.00)/n;
j++;
}
if( att >= 0.75) break;
}
if(j != 0){
cout<<j<<endl;
}else {
cout<<-1<< endl;
}
}
// your code goes here
return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
string ch;
int count=0;
cin>>ch;
int reqa=ceil(n*0.75);
int present=0;
for(int i=0;i<n;i++)
if(ch[i]=='P') present++;
if(present>=reqa){
cout<<0<<endl;
break;
}
int c=0;
for(int i=2;i<(n-2);i++){
if(ch[i]=='A'&&(ch[i-1]=='P'||ch[i-2]=='P')&&(ch[i+1]=='P'||ch[i+2]=='P')){
c++;
if(present+c==reqa){
break;
}
}
}
if(c!=0) cout<<c<<endl;
else cout<<-1<<endl;
}
// your code goes here
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment