# Hoof Paper Scissors Problem USACO help needed

I have my below solution failing only on test case 2.

``````void solve(){
SetIO("hps");
int n;
cin>>n;
vector<int>hoof_pre(n,0),hoof_suff(n,0);
vector<int>pap_pre(n,0),pap_suff(n,0);
vector<int>scis_pre(n,0),scis_suff(n,0);
for(int i=0;i<n;i++){
char c;
cin>>c;
if(c=='H') hoof_pre[i] = hoof_suff[i]=1;
else if(c=='P') pap_pre[i] = pap_suff[i]=1;
else scis_pre[i] = scis_suff[i]=1;
}
for(int i=1;i<n;i++){
hoof_pre[i]+=hoof_pre[i-1];
pap_pre[i]+=pap_pre[i-1];
scis_pre[i]+=scis_pre[i-1];
}
for(int i=n-2;i>-1;i--){
hoof_suff[i]+=hoof_suff[i+1];
pap_suff[i]+=pap_suff[i+1];
scis_suff[i]+=scis_suff[i+1];
}
int v =0;
for(int i=0;i<n-1;i++){
v = max(v,max(hoof_pre[i],max(hoof_pre[i]+pap_suff[i+1],hoof_pre[i]+scis_suff[i+1])));
v = max(v,max(scis_pre[i],max(scis_pre[i]+pap_suff[i+1],scis_pre[i]+hoof_suff[i+1])));
v = max(v,max(pap_pre[i],max(pap_pre[i]+hoof_suff[i+1],pap_pre[i]+scis_suff[i+1])));
}
int ans[] = {v,hoof_suff[n-1],pap_suff[n-1],scis_suff[n-1]};
for(int x : ans) v= max(v,x);
cout<<v;
}

``````

Why donâ€™t you take a look at test case 2 yourself?

1 Like

It is best for you to learn by yourself how to spot errors in your code. Even if it takes a couple of hours. When youâ€™re really stuck in a comp you wouldnâ€™t know what to do. And I totall agree on Benq on how you shouldnâ€™t just ask people how to fix or solve a problem.

@Benq Congrats on coming top 3 in the Deltix Codeforce Round!! Damn youâ€™re too good!