题面

一道介绍ICPC赛制规则的题目,规则同真实规则

1.提交与评测:参赛队伍可以多次提交代码,系统会实时评测并返回结果。如果提交的结果错误,将会有20分钟的罚时,错误次数越多,罚时也会增加。每道题目只有在所有测试数据都正确后才能获得分数。
2.评分标准:比赛的排名主要根据正确解题的数量来评判。如果解题数量相同,则根据总用时进行排名。总用时是从比赛开始到每道题被正确解答的时间与罚时之和。
3.封榜机制:在一些CPC相关赛事中,比赛结束前一小时会进行封榜,封榜后的提交和排名将无法被其他选手看到。

题号为(A~Z)的大写字母,队名不超过10个字符,对于大小写敏感

题目要求,$T$ 组数据($1<T<10000$),每场比赛 $s$ 次提交($2 <s < 2e5$)且每场比赛必定有一个 AC 的提交,问所有可能夺冠的队伍,中间用空格间隔

思路

大模拟

对提交进行操作(处理输入,对时间排序),在这个过程中记录队名并去重
根据队名求出队伍数量,将队名赋值进队伍结构体的数组
先对封榜前的提交进行处理,分为过了的和没过的,同时记录到达封榜时间的提交索引
再对封榜后的提交进行处理,不清楚的直接算过(第一次)
对封榜前下限和封榜后上限分别按从好到坏排序
可能夺冠的条件是,自己的上限要大于所有人的下限
把上限一个一个去与最好的下限比较,得到可能夺冠的队名

需要注意的以下几点:

  • 凡使用 getline 或 stringstream 的,都必须判断是否需要 cin.ignore()
  • 在结构体中,数组初始化不能直接初始化在后面,要单独写成构造函数,如 Team(): befpas(26, false), beftim(26, 0)
  • 用 SUB sub; Team t; 这样的做中间值的,后面要记得赋值回去,当然,直接 传址 最好

总体难度:中位黄~上位黄

代码

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
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

struct SUB{ //提交-结构体
string name, cond; //队名和提交状态
int tihao, time; //题号和提交时间
};

struct Team{
string name; //名字
vector<bool> befpas; //通过题目的位置
vector<int> beftim; //通过那道题的时间
int befcnt; //封榜前通过数
int fbqtim; //封榜前累计总时间(只有通过的才算进去)

int totcnt; //全程通过数
int tottime; //全程总时间
Team(): befpas(26, false), beftim(26, 0),
befcnt(0), fbqtim(0), totcnt(0),tottime(0) {}
};

bool cmp(const SUB& p, const SUB& q){ //根据提交的时间对提交排序
return p.time < q.time;
}

bool cmpshang(const Team& p ,const Team& q){ //排封榜后上限
if(p.totcnt == q.totcnt){
return p.tottime < q.tottime;
}
return p.totcnt > q.totcnt;
}

bool cmpxia(const Team& p ,const Team& q){ //排封榜前下限
if(p.befcnt == q.befcnt){
return p.fbqtim < q.fbqtim;
}
return p.befcnt > q.befcnt;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<SUB> v(n);
vector<string> jigedui; //存储队名和计算队数
unordered_map<string, int> mp; //根据 umap 的 find 优化查找队名的循环
for (int i = 0; i < n; i++) {
string team, res, pid;
int t;
cin >> team >> pid >> t >> res; //直接输入优化 getline 和 stringstream
SUB sub;
int cnt = 0;
sub.name = team;
bool flag = false;
if (mp.find(team) == mp.end()) {
int idx = (int)jigedui.size();
jigedui.push_back(team);
mp[team] = idx;
}
int x = pid[0] - 'A';
sub.tihao = x;
sub.time = t;
sub.cond = res;
cnt++;
v[i] = sub; //别忘记赋值回去
}
sort(v.begin(), v.end(), cmp);
int duishu = jigedui.size();
vector<Team> dui(duishu);
for (int i = 0; i < duishu; i++) {
dui[i].name = jigedui[i];
}
int tiaochu = n; //一定要初始化成n,因为封榜后可能一个提交都没有
for (int i = 0; i < n; i++) {
if (v[i].time >= 240) {
tiaochu = i;
break;
}
string s = v[i].name;
int tj = mp[v[i].name]; //使用 umap 快速查找索引
Team &t = dui[tj]; //通过索引直接拷贝
if (v[i].cond[0] == 'A' && t.befpas[v[i].tihao] == false) { //过了且之前没过
t.totcnt++;
t.befcnt++;
t.befpas[v[i].tihao] = true;
t.beftim[v[i].tihao] += v[i].time; //过了后计算那道题的总时间
t.fbqtim += t.beftim[v[i].tihao]; //那题总时间加到下限时间和该队总时间
t.tottime += t.beftim[v[i].tihao];
} else if (v[i].cond[0] == 'R' && t.befpas[v[i].tihao] == false) {
t.beftim[v[i].tihao] += 20;
}
dui[tj] = t;
}
for (int i = tiaochu; i < n; i++) { //计算封榜后的题目
int tj = mp[v[i].name];
Team &t = dui[tj];
if (v[i].cond[0] == 'U' && t.befpas[v[i].tihao] == false) {
t.totcnt++;
t.befpas[v[i].tihao] = true;
t.beftim[v[i].tihao] += v[i].time;
t.tottime += t.beftim[v[i].tihao];
} else if (v[i].cond[0] == 'R' && t.befpas[v[i].tihao] == false) {
t.beftim[v[i].tihao] += 20;
}
dui[tj] = t;
}
//可能夺冠的条件是上限大于所有人下限,即上限大于最好的下限
//同时从上限最好的开始找可以提前跳出
vector<Team> dui2 = dui;
sort(dui.begin(), dui.end(), cmpshang); //找上限最好的
sort(dui2.begin(), dui2.end(), cmpxia); //找下限最好的
vector<string> re;
int bestcnt = dui[0].totcnt; //把最好的下限拿出来
int besttime = dui[0].tottime;
for (int i = 0; i < duishu; i++) {
if (dui[i].totcnt > dui2[0].befcnt) { //过题数多
re.push_back(dui[i].name);
} else if (dui[i].totcnt == dui2[0].befcnt &&
dui[i].tottime <= dui2[0].fbqtim) { //题数相同时间短
re.push_back(dui[i].name);
} else {
break;
}
}
sort(re.begin(), re.end()); //按字典序排序
for (int i = 0; i < re.size(); i++) {
if (i)
cout << " ";
cout << re[i];
}
cout << endl;
}
return 0;
}

后记

榜单:外榜 - 2025 ICPC Asia EC网络预选赛 - 第一场

补题链接:The 2025 ICPC Asia East Continent Online Contest (I)

与次日修正了:

  • 代码中未按字典序排序的错误
  • 使用直接 cin 的方式优化了 getline(cin,line); 和 stringstream ss(line);
  • 使用 umap 优化了队名查找的逻辑,不再是每次都从数组中遍历,同时将 umap 当时的大小当做索引
  • 在 umap 更容易通过队名找到队伍索引的基础上,用赋值的方式替代了拷贝,int tj = mp[v[i].name]; 和 Team &t = dui[tj];