int main() { int T; cin>>T; //cout<<T<<endl; REP(t, T) { int ans = 0; VVI d; d.PB(VI()); d.PB(VI()); int N; cin>>N; REP(i, N) { char col; int loc; cin>>col>>loc; //cout<<col<<loc<<endl; int ci = col=='O'?0:1; d[ci].PB(i); d[ci].PB(loc); } //cout<<d<<endl; int pi = 0; int ci[2]; int cur[2]; ci[0]=ci[1]=0; cur[0]=cur[1]=1; REP(step, 100*100) { int pushed = 0; int end = 1; REP(col, 2) { if(ci[col]>=d[col].size()/2) continue; end = 0; int p = d[col][ci[col]*2+0]; int loc = d[col][ci[col]*2+1]; if(cur[col]==loc) { if(pi==p) { //cout<<col<<" push "<<cur[col]<<endl; pushed=1; ci[col]++; } else { //cout<<col<<" stay"<<endl; } } else { int dir = loc - cur[col] > 0 ? 1 : -1; cur[col]+=dir; //cout<<col<<" move to "<<cur[col]<<endl; } } if(pushed) pi++; if(end) break; ans++; } cout<<"Case #"<<t+1<<": "<<ans<<endl;; } return 0; }
(反省点)
int main() { int T; cin>>T; //cout<<T<<endl; REP(t, T) { vector<string> com; vector<string> del; string v; int nc, nd, nv; cin>>nc; REP(i, nc) { string tmp; cin>>tmp; com.PB(tmp); } cin>>nd; REP(i, nd) { string tmp; cin>>tmp; del.PB(tmp); } cin>>nv; cin>>v; //cout<<com<<del<<v<<endl; vector<char> w; REP(i, nv) { w.PB(v[i]); if(w.SZ>=2) REP(j, nc) { if(w[w.SZ-2]==com[j][0] && w[w.SZ-1]==com[j][1]) { w.pop_back(); w.pop_back(); w.PB(com[j][2]); } if(w[w.SZ-2]==com[j][1] && w[w.SZ-1]==com[j][0]) { w.pop_back(); w.pop_back(); w.PB(com[j][2]); } } if(w.SZ>=2) REP(j, nd) { if(w[w.SZ-1]==del[j][0]) REP(k, w.SZ-1) { if(w[k]==del[j][1]) { w.clear(); } } if(w[w.SZ-1]==del[j][1]) REP(k, w.SZ-1) { if(w[k]==del[j][0]) { w.clear(); } } } } cout<<"Case #"<<t+1<<": "<<w<<endl;; } return 0; }
int main() { int T; cin>>T; //cout<<T<<endl; REP(t, T) { int n; cin>>n; VI c(n); int x=0; int sum=0; REP(i, n) { cin>>c[i]; x ^= c[i]; sum+=c[i]; } SORT(c); sum -= c[0]; //cout<<c<<endl; if(x==0) { cout<<"Case #"<<t+1<<": "<<sum<<endl; } else { cout<<"Case #"<<t+1<<": NO"<<endl; } } return 0; }
(反省点)
(以下、間違ってますが掲載)
int main() { int T; cin>>T; //cout<<T<<endl; REP(t, T) { int n; int ans=0; cin>>n; VI d(n); REP(i, n) { cin>>d[i]; } cout<<d<<endl; int ans2=0; REP(i, n) { if(i+1!=d[i]) ans2++; } REP(i, n) { if(i+1!=d[i]) { int ti=-1; FOR(j, i+1, n) { if(d[j]==i+1) { ti=j; break; } } swap(d[i], d[ti]); ans+=2; //cout<<d<<endl; } } //cout<<d<<endl; cout<<"Case #"<<t+1<<": "<<ans<<".000000 "<<ans2<<endl; } return 0; }