forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
97 lines (84 loc) · 2.12 KB
/
B.cpp
File metadata and controls
97 lines (84 loc) · 2.12 KB
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
#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define FOREACH(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();++it)
#define CLR(x) memset((x),0,sizeof((x)))
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
class driver {
public:
string name;
int points;
int places[55];
};
vector<driver> mm;
bool cmp1(const driver& a, const driver& b) {
if (a.points != b.points) return b.points < a.points;
REP(i,50) {
if (a.places[i] != b.places[i]) return b.places[i] < a.places[i];
}
return false;
}
bool cmp2(const driver& a, const driver& b) {
if (a.places[0] != b.places[0]) return b.places[0] < a.places[0];
if (a.points != b.points) return b.points < a.points;
FOR(i,1,49) {
if (a.places[i] != b.places[i]) return b.places[i] < a.places[i];
}
return false;
}
int scores[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
map<string, int> mp;
map<string, int>::iterator itr;
void run() {
mp.clear();
mm.clear();
int idx = 0;
int T;
cin >> T;
REP(t,T) {
int n;
cin >> n;
REP(i,n) {
string name;
cin >> name;
itr = mp.find(name);
if (itr == mp.end()) {
driver d = driver();
d.name = name;
d.points = 0;
memset(d.places, 0, sizeof(d.places));
mm.push_back(d);
mp[name] = idx++;
}
int id = mp[name];
if (i < 10) mm[id].points += scores[i];
mm[id].places[i] += 1;
}
}
sort(mm.begin(), mm.end(), cmp1);
cout << mm[0].name << endl;
sort(mm.begin(), mm.end(), cmp2);
cout << mm[0].name << endl;
}
int main() {
run();
return 0;
}