Skip to content

Commit 51a4e20

Browse files
committed
Codeforces Gym: SYSU Collegiate Programming Contest 2024 (SYSUCPC 2024), Final
1 parent 0f7bdbe commit 51a4e20

10 files changed

+695
-0
lines changed

Codeforces Gym/105631A.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file 105631A.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-01-03
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
void solve(void) {
20+
int x, y, z;
21+
cin >> x >> y >> z;
22+
cout << min({x / 2, y, z}) << endl;
23+
return;
24+
}
25+
26+
bool mem2;
27+
28+
int main() {
29+
ios::sync_with_stdio(false), cin.tie(nullptr);
30+
#ifdef LOCAL
31+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
32+
#endif
33+
34+
int _ = 1;
35+
cin >> _;
36+
while (_--) solve();
37+
38+
#ifdef LOCAL
39+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
40+
#endif
41+
return 0;
42+
}

Codeforces Gym/105631C.cpp

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* @file 105631C.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-01-03
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 100005
20+
21+
typedef tuple<int, int64_t, int> tili;
22+
23+
set<tili> S;
24+
25+
int pel[maxn][27];
26+
tili cur[maxn];
27+
28+
void solve(void) {
29+
int n, m;
30+
cin >> n >> m;
31+
32+
for (int i = 0; i <= n; i++) S.emplace(cur[i] = {0, 0, i});
33+
34+
int rank0 = 1;
35+
while (m--) {
36+
string tim;
37+
int team;
38+
char prob;
39+
string status;
40+
cin >> tim >> team >> prob >> status;
41+
42+
int clk = stoi(tim.substr(0, 2)) * 60 + stoi(tim.substr(3, 2));
43+
44+
if (pel[team][prob - 'A'] == -1) continue;
45+
46+
if (status == "RJ") {
47+
pel[team][prob - 'A'] += 20;
48+
continue;
49+
}
50+
51+
tili oCur = cur[team];
52+
get<0>(cur[team])--, get<1>(cur[team]) += clk + pel[team][prob - 'A'];
53+
pel[team][prob - 'A'] = -1;
54+
55+
if (team) {
56+
S.erase(oCur);
57+
S.insert(cur[team]);
58+
if (cur[team] < cur[0] && cur[0] < oCur) rank0++;
59+
continue;
60+
}
61+
62+
int ork = rank0;
63+
64+
auto p = S.erase(S.find(oCur));
65+
while (p != S.begin() && cur[0] < *prev(p)) p--, rank0--;
66+
S.insert(cur[0]);
67+
68+
cout << tim << ' ' << prob << " #" << ork << " -> #" << rank0 << endl;
69+
}
70+
71+
return;
72+
}
73+
74+
bool mem2;
75+
76+
int main() {
77+
ios::sync_with_stdio(false), cin.tie(nullptr);
78+
#ifdef LOCAL
79+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
80+
#endif
81+
82+
int _ = 1;
83+
while (_--) solve();
84+
85+
#ifdef LOCAL
86+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
87+
#endif
88+
return 0;
89+
}

Codeforces Gym/105631D.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @file 105631D.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-01-03
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 200005
20+
21+
vector<int> graph[maxn];
22+
int64_t f[maxn], g[maxn], siz[maxn];
23+
24+
void dfs1(int p, int pre = -1) {
25+
siz[p] = 1, f[p] = 0;
26+
for (auto q : graph[p])
27+
if (q != pre) dfs1(q, p), f[p] += f[q] + siz[q] * (siz[q] - 1), siz[p] += siz[q];
28+
return;
29+
}
30+
31+
void dfs2(int p, int pre = -1) {
32+
g[p] = f[p];
33+
for (auto q : graph[p]) {
34+
if (q == pre) continue;
35+
f[p] -= f[q] + siz[q] * (siz[q] - 1), siz[p] -= siz[q];
36+
f[q] += f[p] + siz[p] * (siz[p] - 1), siz[q] += siz[p];
37+
dfs2(q, p);
38+
f[q] -= f[p] + siz[p] * (siz[p] - 1), siz[q] -= siz[p];
39+
f[p] += f[q] + siz[q] * (siz[q] - 1), siz[p] += siz[q];
40+
}
41+
return;
42+
}
43+
44+
void solve(void) {
45+
int n;
46+
cin >> n;
47+
for (int i = 1, x, y; i < n; i++) cin >> x >> y, graph[x].push_back(y), graph[y].push_back(x);
48+
49+
dfs1(1);
50+
51+
dfs2(1);
52+
53+
for (int i = 1; i <= n; i++) cout << g[i] / 2 << endl;
54+
55+
return;
56+
}
57+
58+
bool mem2;
59+
60+
int main() {
61+
ios::sync_with_stdio(false), cin.tie(nullptr);
62+
#ifdef LOCAL
63+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
64+
#endif
65+
66+
int _ = 1;
67+
while (_--) solve();
68+
69+
#ifdef LOCAL
70+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
71+
#endif
72+
return 0;
73+
}

Codeforces Gym/105631E.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @file 105631E.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-01-03
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
void solve(void) {
20+
int n;
21+
cin >> n;
22+
string s;
23+
cin >> s;
24+
cout << (s.front() == '1' || s.back() == '1' ? "Alice" : "Bob") << endl;
25+
return;
26+
}
27+
28+
bool mem2;
29+
30+
int main() {
31+
ios::sync_with_stdio(false), cin.tie(nullptr);
32+
#ifdef LOCAL
33+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
34+
#endif
35+
36+
int _ = 1;
37+
cin >> _;
38+
while (_--) solve();
39+
40+
#ifdef LOCAL
41+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
42+
#endif
43+
return 0;
44+
}

Codeforces Gym/105631F.cpp

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* @file 105631F.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-01-03
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
string a;
20+
bool chk[27];
21+
int cnt[27], len[27], nxt[27][27], jmp[27];
22+
23+
void dfs(int p) {
24+
if (jmp[p] >= 0)
25+
dfs(jmp[p]), len[p] = len[jmp[p]] + 1;
26+
else
27+
len[p] = (chk[p] ? 1 : -1);
28+
return;
29+
}
30+
31+
void solve(void) {
32+
int n;
33+
cin >> n >> a, a = ' ' + a;
34+
for (int i = 1; i <= n; i++) cnt[a[i] - 'a']++;
35+
for (int i = 1; i < n; i++) nxt[a[i] - 'a'][a[i + 1] - 'a']++;
36+
37+
int q;
38+
cin >> q;
39+
while (q--) {
40+
int pos;
41+
char c;
42+
cin >> pos >> c;
43+
44+
cnt[a[pos] - 'a']--;
45+
if (pos > 1) nxt[a[pos - 1] - 'a'][a[pos] - 'a']--;
46+
if (pos < n) nxt[a[pos] - 'a'][a[pos + 1] - 'a']--;
47+
a[pos] = c;
48+
if (pos > 1) nxt[a[pos - 1] - 'a'][a[pos] - 'a']++;
49+
if (pos < n) nxt[a[pos] - 'a'][a[pos + 1] - 'a']++;
50+
cnt[a[pos] - 'a']++;
51+
52+
int mx = 0;
53+
for (int i = 0; i < 26; i++) mx = max(mx, cnt[i]);
54+
for (int i = 0; i < 26; i++) {
55+
jmp[i] = -1;
56+
if (cnt[i] < mx || a[n] - 'a' == i) continue;
57+
for (int j = 0; j < 26; j++)
58+
if (nxt[i][j] > 0) {
59+
if (jmp[i] == -1)
60+
jmp[i] = j;
61+
else
62+
jmp[i] = -2;
63+
}
64+
if (jmp[i] >= 0 && cnt[jmp[i]] < mx) jmp[i] = -1;
65+
}
66+
for (int i = 0; i < 26; i++) chk[i] = (cnt[i] == mx), len[i] = 0;
67+
for (int i = 0; i < 26; i++)
68+
if (!len[i]) dfs(i);
69+
int ans = 0, mxlen = 0;
70+
for (int i = 0; i < 26; i++)
71+
if (len[i] > 0) ans += len[i], mxlen = max(mxlen, len[i]);
72+
cout << 3 * ans - mxlen << endl;
73+
}
74+
return;
75+
}
76+
77+
bool mem2;
78+
79+
int main() {
80+
ios::sync_with_stdio(false), cin.tie(nullptr);
81+
#ifdef LOCAL
82+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
83+
#endif
84+
85+
int _ = 1;
86+
while (_--) solve();
87+
88+
#ifdef LOCAL
89+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
90+
#endif
91+
return 0;
92+
}

0 commit comments

Comments
 (0)