kengo92iの日記

プログラミングとかやったことの記録を書いていきます。

AOJ-1187 : ICPC Ranking

ICPC Ranking | Aizu Online Judge

ICPCの順位システムの簡易版を実装する。ログデータを入力にして、それぞれの順位を確定させる。各順位の区切りは ',' を使い、同じ順位が居る場合は '=' で表現する。


構造体Teamを定義して、ACした時とWAした時の関数を作る。構造体の中に順位付けの規則を定義して、ログデータを読み込む。最後にソートすることで順位が決まる。同じ順位のチームの処理は、1つ前のチームとAC状況と経過時間が一緒なら'='で区切る、それ以外は','で区切る。

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1187&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Team 
{
	int id;
	int AC;
	int time;
	vector<int> WA;
	Team(int ID,int P):id(ID),AC(0),time(0),WA(P+1,0){}

	void accepted(int m, int p){
		AC += 1;
		time += (m + 20*WA[p]);
	}

	void wrongAnswer(int p){
		WA[p] += 1;
	}

	bool operator<( const Team& right ) const 
	{
		if(AC == right.AC)
		{
			if(time == right.time){
				return id > right.id;
			}else{
				return time < right.time;
			}
		}
		else{
			return AC > right.AC;
		}
	}
};


int main()
{
	int M,T,P,R;
	int m,t,p,j;
	while(true)
	{
		cin >> M >> T >> P >> R;
		if( !M && !T && !P && !R ){ break; }
		vector<Team> teams;
		rep(i,T){
			teams.push_back(Team(i+1,P));
		}

		rep(nth,R)
		{
			cin >> m >> t >> p >> j;
			if(j==0){
				teams[--t].accepted(m,p);
			}else{
				teams[--t].wrongAnswer(p);
			}
		}

		sort(ALL(teams));
		
		rep(i,T){
			if(i!=0){
				char sep=',';
				Team prev = teams[i-1];
				if(teams[i].AC==prev.AC && teams[i].time==prev.time){ sep='='; }
				cout << sep;
			}
			cout << teams[i].id;
		}
		cout << endl;
	}
	return 0;
}