-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuva-10258.cpp
216 lines (170 loc) · 4.92 KB
/
uva-10258.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <bits/stdc++.h>
using namespace std;
/* something starts */
/* something ends */
/* typedef starts */
typedef long long ll;
typedef unsigned long long ull;
/* typedef ends */
/* macro starts */
#define PI acos(-1.0)
#define MAX 101
#define MAX_P 11
/* macro ends */
struct LOG
{
int teamNo;
int problemNo;
int mm;
char verdict;
LOG(int t, int p, int m, char v)
{
teamNo = t;
problemNo = p;
mm = m;
verdict = v;
}
bool operator<(const LOG &l)
{
/*
if (mm == l.mm) {
if (verdict == l.verdict) {
return teamNo < l.teamNo;
}
return verdict <= l.verdict;
}
*/
return mm < l.mm;
}
};
struct TEAM
{
int teamNumber;
int solvedCount;
int totalTime;
int solved[MAX_P];
int tryCount[MAX_P];
int _rank;
bool tried; /// tried at least 1 problem
bool operator<(const TEAM &t)
{
if (solvedCount == t.solvedCount) {
if (totalTime == t.totalTime) {
return teamNumber < t.teamNumber;
}
return totalTime < t.totalTime;
}
return solvedCount > t.solvedCount;
}
};
TEAM all[MAX];
void initialize()
{
for (int i = 1; i < MAX; i++) {
all[i].teamNumber = i;
all[i].solvedCount = 0;
all[i].totalTime = 0;
for (int j = 0; j < MAX_P; j++) {
all[i].solved[j] = all[i].tryCount[j] = 0;
}
all[i]._rank = 0;
all[i].tried = false;
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int test, t = 0, i, totalTeam;
int teamNo, mm, problemNo;
char verdict, ch;
char logText[100], temp[100];
vector<LOG>allLog;
scanf("%d", &test);
getchar();
getchar();
while (true) {
initialize();
totalTeam = 0;
while (true) {
ch = getchar();
if (ch == -1 || ch == '\n') {
t++;
break;
}
else {
ungetc(ch, stdin);
}
gets(logText);
//puts(logText);
sscanf(logText, "%d %d %d %c", &teamNo, &problemNo, &mm, &verdict);
totalTeam = max(totalTeam, teamNo);
/*
if (verdict == 'C') {
verdict = 'Y';
}
else if (verdict == 'I') {
verdict = 'N';
}
*/
if (verdict != 'C' && verdict != 'I') {
verdict = 'X'; /// submission will be ignored
}
allLog.push_back(LOG(teamNo, problemNo, mm, verdict));
}
//t++;
if (t != 1) {
printf("\n");
}
//printf("T = %d\n", t);
sort(allLog.begin(), allLog.end());
/*
for (i = 0; i < allLog.size(); i++) {
sprintf(temp, "%d %d %d %c", allLog[i].teamNo, allLog[i].problemNo, allLog[i].mm, allLog[i].verdict);
puts(temp);
}
*/
for (i = 0; i < allLog.size(); i++) {
teamNo = allLog[i].teamNo;
problemNo = allLog[i].problemNo;
mm = allLog[i].mm;
verdict = allLog[i].verdict;
all[teamNo].tried = true;
if (all[teamNo].solved[problemNo] == 1 || verdict == 'X') {
continue;
}
else if (verdict == 'I' && all[teamNo].solved[problemNo] == -1) {
all[teamNo].tryCount[problemNo]++;
}
else if (verdict == 'I' && all[teamNo].solved[problemNo] == 0) {
all[teamNo].solved[problemNo] = -1;
all[teamNo].tryCount[problemNo]++;
}
else if (verdict == 'C') {
all[teamNo].solved[problemNo] = 1;
all[teamNo].solvedCount++;
all[teamNo].totalTime += mm + (all[teamNo].tryCount[problemNo] * 20);
//printf("%d\n", all[teamNo].totalTime);
//sprintf(temp, "%d %c %d:%02d %c", allLog[i].teamNo, allLog[i].problemNo, allLog[i].hh, allLog[i].mm, allLog[i].verdict);
//puts(temp);
}
}
sort(all + 1, all + 1 + totalTeam);
all[0].solvedCount = all[1].solvedCount;
all[0].totalTime = all[1].totalTime;
all[0]._rank = 1;
for (i = 1; i <= totalTeam; i++) {
if (all[i].tried) {
printf("%d %d %d\n", all[i].teamNumber, all[i].solvedCount, all[i].totalTime);
}
}
allLog.clear();
if (t == test) {
break;
}
}
return 0;
}