-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10258.cpp
121 lines (112 loc) · 2.48 KB
/
P10258.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <stdio.h>
#include <vector>
#include <tuple>
#include <algorithm>
typedef std::vector<std::tuple<int,int,int> > Vec;
int nextInt(char *w, int &idx) {
char c;
while(!isdigit(c = w[idx++]))
if(!isprint(c))
return -1;
int ret = c-'0';
while(isdigit(c = w[idx++]))
ret = 10*ret + c-'0';
return ret;
}
char nextChar(char *w, int &idx) {
char c;
while(!isalpha(c = w[idx++]))
if(!isprint(c))
return -1;
return c;
}
struct Contestant {
int incorrect[9];
int correctTimes[9];
bool anySubmissions;
void addOther() {
anySubmissions = true;
}
void addIncorrect(int problem) {
if(correctTimes[problem] >= 0)
return;
++incorrect[problem];
anySubmissions = true;
}
void addCorrect(int problem, int time) {
if(correctTimes[problem] >= 0)
return;
correctTimes[problem] = time;
anySubmissions = true;
}
void reset() {
for(int i = 0; i < 9; ++i) {
incorrect[i] = 0;
correctTimes[i] = -1;
}
anySubmissions = false;
}
int countCorrect() {
int ret = 0;
for(int i = 0; i < 9; ++i) {
if(correctTimes[i] != -1)
++ret;
}
return ret;
}
int penalty() {
int ret = 0;
for(int i = 0; i < 9; ++i) {
if(correctTimes[i] == -1)
continue;
ret += 20 * incorrect[i] + correctTimes[i];
}
return ret;
}
};
int main() {
Contestant c[100];
char w[100];
// Read cases:
int idx = 0;
gets(w);
int cases = nextInt(w, idx);
gets(w);
for(int cas = 0; cas < cases; ++cas) {
if(cas != 0)
std::cout << std::endl;
for(int i = 0; i < 100; ++i)
c[i].reset();
while(gets(w)) {
idx = 0;
int contestant = nextInt(w, idx);
if(contestant <= 0)
break;
--contestant;
int problem = nextInt(w, idx);
--problem;
int time = nextInt(w, idx);
char L = nextChar(w, idx);
if(L == 'C')
c[contestant].addCorrect(problem, time);
else if(L == 'I')
c[contestant].addIncorrect(problem);
else
c[contestant].addOther();
}
// Sort:
Vec v;
for(int i = 0; i < 100; ++i) {
if(!c[i].anySubmissions)
continue;
v.push_back(std::tuple<int,int,int>(-c[i].countCorrect(), c[i].penalty(), i));
}
std::sort(v.begin(), v.end());
// Print score board:
for(Vec::const_iterator it = v.begin(); it != v.end(); ++it) {
std::cout << (1+std::get<2>(*it)) << " " << -std::get<0>(*it) << " "<< std::get<1>(*it) << std::endl;
}
}
return 0;
}