2009-04-26
SRM209 Div1 Easy (300pt): MedalTable
Algorithm Tutorials: How To Find a Solution (by Dumitru) より
- 自家製 split() を使用
- mapでエラーが出るので使い方忘れた?と思ったらmという変数をintでも使ってたorz
- 240.55 points(14'54''), Passed system test.
#define sz(a) int((a).size()) #define pb push_back #define all(c) (c).begin(),(c).end() #define tr(c,i) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) #define rep(var,n) for(int var=0;var<(n);var++) #define found(s,e) ((s).find(e)!=(s).end()) class MedalTable { public: vector<string> generate(vector<string> results) { int rn=sz(results); map<string,int> m; rep(i,rn){ vector<string> cs=split(results[i]); for(int j=0,mk=4096;j<3;j++,mk>>=6){ string cnt=cs[j]; if(found(m,cnt)){ m[cnt]+=mk; }else{ m[cnt]=mk; } } } vector<pair<int,string> > sc; tr(m,it){ sc.pb(make_pair(-it->second,it->first)); } sort(all(sc)); vector<string> ret; tr(sc,it){ stringstream ss; ss << it->second << " "; int score=-it->first; ss << (score >> 12) << " " << ((score >> 6) & 63) << " " << (score & 63); ret.pb(ss.str()); } return ret; } };