結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー antaanta
提出日時 2016-11-18 04:24:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,766 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 186,592 KB
実行使用メモリ 4,532 KB
最終ジャッジ日時 2023-08-17 08:31:07
合計ジャッジ時間 3,791 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 12 ms
4,532 KB
testcase_20 AC 9 ms
4,488 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 11 ms
4,460 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#ifdef NDEBUG
#error assert is disabled!
#endif

template<typename T>
T readNatural(T lo, T up) {
	assert(0 <= lo && lo <= up);
	T x = 0;
	while(1) {
		int d = getchar();
		if(!('0' <= d && d <= '9')) {
			ungetc(d, stdin);
			break;
		}
		d -= '0';
		assert(d <= up && x <= (up - d) / 10);
		x = x * 10 + d;
	}
	assert(lo <= x && x <= up);
	return x;
}

void readSpace() { int c = getchar(); assert(c == ' '); }
static bool read_eof = false;
void readEOL() {
	int c = getchar();
	if(c == EOF) {
		assert(!read_eof);
		read_eof = true;
	} else {
		assert(c == '\n');
	}
}
void readEOF() {
	assert(!read_eof);
	int c = getchar();
	assert(c == EOF);
	read_eof = true;
}


int readString(char *buf, int minLen, int maxLen, bool charactors[128]) {
	assert(0 <= minLen && minLen <= maxLen);
	int len = 0;
	while(1) {
		int c = getchar();
		if(!(0 <= c && c < 128) || !charactors[c]) {
			ungetc(c, stdin);
			break;
		}
		assert(len < maxLen);
		buf[len ++] = c;
	}
	assert(minLen <= len && len <= maxLen);
	buf[len] = 0;
	return len;
}

struct Contestant {
	std::vector<int> scores;
	int totalScore;
	int lastTime;

	Contestant() : totalScore(0), lastTime(0) {}
};

int main() {
	bool lowercases[128] = {}, uppercases[128] = {};
	for(int a = 0; a < 26; ++ a) {
		lowercases['a' + a] = true;
		uppercases['A' + a] = true;
	}

	int N = readNatural(1, 26);
	readEOL();
	vector<int> L(N);
	for(int i = 0; i < N; ++ i) {
		if(i != 0) readSpace();
		L[i] = readNatural(1, 6);
	}
	readEOL();
	int T = readNatural(1, 4000);
	readEOL();

	std::map<std::string, Contestant> contestants;
	std::vector<int> count(N, 0);
	for(int i = 0; i < T; ++ i) {
		char name[17], P[2];
		readString(name, 1, 16, lowercases);
		readSpace();
		readString(P, 1, 1, uppercases);
		readEOL();
		int p = *P - 'A';
		assert(0 <= p && p < N);
		int stars = L[p];
		int rank = ++ count[p];
		int score = 50 * stars + 50 * stars * 10 / (8 + 2 * rank);
		assert(score > 0);
		auto &c = contestants[name];
		if(c.scores.empty())
			c.scores.assign(N, 0);
		assert(c.scores[p] == 0);
		c.scores[p] = score;
		c.totalScore += score;
		c.lastTime = i + 1;
	}
	std::vector<std::pair<std::string, Contestant>> leaderboard(contestants.begin(), contestants.end());
	sort(leaderboard.begin(), leaderboard.end(), [&](auto &&x, auto &&y) {
		if(x.second.totalScore != y.second.totalScore)
			return x.second.totalScore > y.second.totalScore;
		else
			return x.second.lastTime < y.second.lastTime;
	});
	for(int i = 0; i < (int)leaderboard.size(); ++ i) {
		const auto &p = leaderboard[i];
		printf("%d %s", i + 1, p.first.c_str());
		for(int j = 0; j < N; ++ j)
			printf(" %d", p.second.scores[j]);
		printf(" %d\n", p.second.totalScore);
	}
	readEOF();
	return 0;
}
0