So For this particular problem, : CONFLIP Problem - CodeChef
I wrote this code:
#include <iostream>
using namespace std;
int main() {
int T;
cin>>T;
while((T--)&&T<=10){
int g;
cin>>g;
while((g--)&&(g<=2000)){
int initial,rounds,predict;
cin>>initial>>rounds>>predict; ///i,n,q resp
int coins[rounds];
if(initial==1){ /// if all are to be heads, fill them up all with 1s.
for(int i=0;i<rounds;i++){
coins[i]=1;
}
}
else if(initial==2){ // if all are to be tails, fill them up all with 2s.
for(int i=0;i<rounds;i++){
coins[i]=2;
}
}
for(int i=0;i<rounds;i++){ // first i=0, j=0, so if c[i]=1,make it 2.
for(int j=0;j<=i;j++){
if(coins[j]==1) coins[j]=2;
else if(coins[j]==2) coins[j]=1;
}
}
int heads=0,tails=0;
for(int i=0;i<rounds;i++){
coins[i]==1?heads++:tails++;
}
predict==1?cout<<heads<<endl:cout<<tails<<endl;
}
}
}
It says : Runtime error (OTHER), but my code prints the output as per the given sample input.