P17745 题解
该题解为本题的官方题解。
我们需要根据不同的赛制,统计选手每题得分,计算总分后按规则排名:总分高的靠前,总分相同则排名一致且按姓名字典序升序输出即可。
- OI 赛制:每题取最后一次提交得分;
- IOI 赛制:每题取最高一次提交得分。
代码如下:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<string, map<int, int>> mp1, mp2;
map<string, int> vis;
string names[N], op, s;
int n, m, k, cnt, pid, sco, cur = 1;
struct node
{
string na;
int tot;
} a[N];
bool cmp(node x, node y)
{
if (x.tot != y.tot) return x.tot > y.tot;
return x.na < y.na;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for (int i = 0; i < m; i++)
{
cin >> s >> pid >> sco;
mp1[s][pid] = sco;
if (sco > mp2[s][pid]) mp2[s][pid] = sco;
if (!vis[s]) vis[s] = 1, names[cnt++] = s;
}
cin >> op;
for (int i = 0; i < cnt; i++)
{
a[i].na = names[i], a[i].tot = 0;
if (op == "OI")
for (auto t : mp1[names[i]])
a[i].tot += t.second;
else
for (auto t : mp2[names[i]])
a[i].tot += t.second;
}
sort(a, a + cnt, cmp);
for (int i = 0; i < cnt; i++)
{
if (i > 0 && a[i].tot != a[i - 1].tot) cur = i + 1;
cout << cur << " " << a[i].na << " " << a[i].tot << "\n";
}
return 0;
}