↓だめな例です。。
class PalindromeGame { public: int isV(string& s) { int a = s.size() / 2; REP(i, a) if(s[i]!=s[s.size()-i-1]) return 0; return 1; } int isPair(string& a, string& b) { REP(i, a.SZ) if(a[i]!=b[a.SZ-i-1]) return 0; return 1; } int getMaximum(vector <string> front, vector <int> back) { printf("%s %d\n", __FILE__, __LINE__); int maxans = 0; REP(ca, 2) { VI used(front.SZ); //cout<<used<<endl; int ansv = 0; if(ca==0) { // find type V int ansv_idx = -1; REP(i, front.SZ) if(isV(front[i]) && ansv < back[i]) { ansv_idx = i; ansv = back[i]; }; cout<<ansv<<endl; if(ansv_idx!=-1) used[ansv_idx] = 1; } //cout<<used<<endl; // find pairs int ansp = 0; REP(i, front.SZ) { int maxv_j = -1; int maxv = 0; FOR(j, i+1, front.SZ) { if(used[i]) continue; if(used[j]) continue; if(isPair(front[i], front[j])) { maxv = back[i]+back[j]; maxv_j = j; } } if(maxv_j!=-1) { ansp += maxv; used[i] = used[maxv_j] = 1; } } //cout<<used<<endl; cout<<ca<<" "<<ansp<<endl; int ans = ansv + ansp; cout<<ca<<" "<<ans<<endl; if(maxans<ans) maxans = ans; } cout<<maxans<<endl; return maxans; }