Codeforces Round#24 B:F1 Champions

keyword

シミュレーション C++

概要

コンテスト(複数)の結果が与えられる。各コンテストでは1位から順にp[i]ポイントが与えられる。ここでポイント、1位の回数、2位の回数、…で順位付けしたときのトップと1位の回数、ポイント、2位の回数、…で順位付けしたときのトップをそれぞれ出力する問題。
どう見ても実装ゲーなのでひたすら手を動かす。こういうのは書いてる途中は退屈だけど一発で通るとやっぱり嬉しい。

typedef pair<int, vector<int> > P;
typedef pair< pair<int, int>, vector<int> > Q;

int point[] = {25,18,15,12,10,8,6,4,2,1};
int sz = 10;

int main(){
    int t, i,j, tt;
    cin >> t;
    string name;
    map<string, P> pre;
    map<string, Q> post;
    vector< vector<string> > result(t);
    vector<int> tmp(50,0);
    REP(i,t){
        cin >> tt;
        REP(j,tt){
            cin >> name;
            pre[name] = MP(0,tmp);
            post[name] = MP(MP(0,0),tmp);
            result[i].PB(name);
        }
    }
    REP(i,t){
        REP(j,SZ(result[i])){
            if(j<sz){
                pre[result[i][j]].fs += point[j];
            }
            pre[result[i][j]].sc[j]++;
        }
    }
    vector< pair<P, string> > pp;
    vector< pair<Q, string> > qq;
    EACH(pre,it){
        post[it->fs] = MP(MP(it->sc.sc[0], it->sc.fs), it->sc.sc);
        post[it->fs].sc[0] = 0;
        pp.PB(MP(it->sc, it->fs));
    }
    EACH(post,it){
        qq.PB(MP(it->sc, it->fs));
    }
    sort(ALL(pp));
    sort(ALL(qq));
    cout << pp[SZ(pp)-1].sc << endl;
    cout << qq[SZ(qq)-1].sc << endl;
    return 0;
}