結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー antaanta
提出日時 2016-11-18 04:24:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 2,766 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 190,300 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-26 03:36:29
合計ジャッジ時間 3,301 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0