↓だめな例です。。
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; }
class ColorfulRabbits { public: int getMinimum(vector <int> re) { map<int, int> m; REP(i, re.SZ) { if(m.find(re[i]+1) == m.end()) m[re[i]+1] = 0; m[re[i]+1]++; } int ans = 0; for( map<int, int>::const_iterator p = m.begin(); p!=m.end(); p++ ) { //cout << p->first << ": " << p->second << " " << endl; ans += (p->second + p->first - 1) / p->first * p->first; } return ans; }
class SimpleGuess { public: int getMaximum(vector <int> hints) { sort(hints.B, hints.E); cout<<hints<<endl; int xy = 0; REP(i, hints.SZ) REP(j, hints.SZ) { if(i==j) continue; int x = hints[i] + hints[j]; int y = hints[i] - hints[j]; if(x&1) continue; if(y&1) continue; if(xy<x*y) xy=x*y; } return xy/4; }