Skip to content

Commit acab386

Browse files
committed
Codeforces Round 1038, Div. 1 + Div. 2
1 parent 98a7d1d commit acab386

5 files changed

Lines changed: 301 additions & 0 deletions

File tree

Codeforces/2122A.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @file 2122A.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-19
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, m;
21+
cin >> n >> m;
22+
if (n > m) swap(n, m);
23+
if (n == 1 || (n == 2 && m == 2)) return cout << "NO" << endl, void();
24+
cout << "YES" << 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/2122B.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @file 2122B.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-19
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+
int a[maxn], b[maxn], c[maxn], d[maxn];
22+
23+
void solve(void) {
24+
int n;
25+
cin >> n;
26+
int64_t ans = 0;
27+
for (int i = 1; i <= n; i++) {
28+
cin >> a[i] >> b[i] >> c[i] >> d[i];
29+
if (b[i] > d[i])
30+
ans += a[i] + (b[i] - d[i]);
31+
else if (a[i] > c[i])
32+
ans += a[i] - c[i];
33+
}
34+
cout << ans << endl;
35+
return;
36+
}
37+
38+
bool mem2;
39+
40+
int main() {
41+
ios::sync_with_stdio(false), cin.tie(nullptr);
42+
#ifdef LOCAL
43+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
44+
#endif
45+
46+
int _ = 1;
47+
cin >> _;
48+
while (_--) solve();
49+
50+
#ifdef LOCAL
51+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
52+
#endif
53+
return 0;
54+
}

Codeforces/2122C.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @file 2122C.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-19
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+
using pii = pair<int, int>;
22+
23+
int a[maxn], b[maxn];
24+
bool sa[maxn], sb[maxn];
25+
26+
void solve(void) {
27+
int n;
28+
cin >> n;
29+
vector<pii> va, vb;
30+
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i], va.emplace_back(a[i], i), vb.emplace_back(b[i], i);
31+
sort(va.begin(), va.end()), sort(vb.begin(), vb.end());
32+
for (int i = 0; i < n; i++) sa[va[i].second] = sb[vb[i].second] = i < n / 2;
33+
queue<int> S[4];
34+
for (int i = 1; i <= n; i++) S[sa[i] << 1 | sb[i]].push(i);
35+
assert(S[0].size() == S[3].size()), assert(S[1].size() == S[2].size());
36+
for (int t = 0; t < 2; t++)
37+
while (!S[t].empty()) {
38+
int p = S[t].front(), q = S[t ^ 3].front();
39+
S[t].pop(), S[t ^ 3].pop();
40+
cout << p << ' ' << q << endl;
41+
}
42+
return;
43+
}
44+
45+
bool mem2;
46+
47+
int main() {
48+
ios::sync_with_stdio(false), cin.tie(nullptr);
49+
#ifdef LOCAL
50+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
51+
#endif
52+
53+
int _ = 1;
54+
cin >> _;
55+
while (_--) solve();
56+
57+
#ifdef LOCAL
58+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
59+
#endif
60+
return 0;
61+
}

Codeforces/2122D.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* @file 2122D.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-19
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 5005
20+
21+
vector<vector<int>> graph;
22+
bool vis[2][maxn];
23+
int wait[2][maxn], ptr[maxn];
24+
25+
void solve(void) {
26+
int n, m;
27+
cin >> n >> m;
28+
graph.clear(), graph.resize(n + 1);
29+
for (int i = 1, x, y; i <= m; i++) cin >> x >> y, graph[x].push_back(y), graph[y].push_back(x);
30+
for (int i = 1; i <= n; i++) vis[0][i] = false, wait[0][i] = 1e8, ptr[i] = 0;
31+
vis[0][1] = true, wait[0][1] = 0;
32+
for (int t = 0;; t++) {
33+
int x = t & 1;
34+
if (vis[x][n]) {
35+
cout << t << ' ' << wait[x][n] << endl;
36+
return;
37+
}
38+
for (int i = 1; i <= n; i++) vis[!x][i] = false, wait[!x][i] = 1e8;
39+
for (int i = 1; i <= n; i++) {
40+
if (!vis[x][i]) continue;
41+
vis[!x][i] = true, wait[!x][i] = min(wait[!x][i], wait[x][i] + 1);
42+
int j = graph[i][ptr[i]];
43+
vis[!x][j] = true, wait[!x][j] = min(wait[!x][j], wait[x][i]);
44+
}
45+
for (int i = 1; i <= n; i++)
46+
if (++ptr[i] == (int)graph[i].size()) ptr[i] = 0;
47+
}
48+
return;
49+
}
50+
51+
bool mem2;
52+
53+
int main() {
54+
ios::sync_with_stdio(false), cin.tie(nullptr);
55+
#ifdef LOCAL
56+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
57+
#endif
58+
59+
int _ = 1;
60+
cin >> _;
61+
while (_--) solve();
62+
63+
#ifdef LOCAL
64+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
65+
#endif
66+
return 0;
67+
}

Codeforces/2122E.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @file 2122E.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-19
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 505
20+
#define mod 998244353
21+
22+
int a[3][maxn];
23+
int64_t f[maxn][maxn];
24+
25+
int Mod(int x) { return x >= mod ? x - mod : x; }
26+
27+
void solve(void) {
28+
int n, k;
29+
cin >> n >> k;
30+
for (int i = 1; i <= 2; i++)
31+
for (int j = 1; j <= n; j++) cin >> a[i][j];
32+
33+
for (int i = 1; i <= n; i++)
34+
for (int j = 0; j <= k; j++) f[i][j] = 0;
35+
36+
f[n][0] = 1;
37+
for (int i = n - 1; i >= 1; i--) {
38+
vector<int> cnt(k * 2 + 1, 0);
39+
for (int d = (a[2][i] == -1 ? 1 : a[2][i]); d <= (a[2][i] == -1 ? k : a[2][i]); d++)
40+
for (int u = (a[1][i + 1] == -1 ? 1 : a[1][i + 1]); u <= (a[1][i + 1] == -1 ? k : a[1][i + 1]); u++)
41+
cnt[d - u + k]++;
42+
43+
for (int v = -k; v <= 0; v++)
44+
for (int j = 0; j <= k; j++) f[i][min(k, -v + j)] = (f[i][min(k, -v + j)] + f[i + 1][j] * cnt[v + k]) % mod;
45+
46+
int64_t pre = f[i + 1][0];
47+
for (int v = 1; v <= +k; v++) pre = Mod(pre + f[i + 1][v]), f[i][0] = (f[i][0] + pre * cnt[v + k]) % mod;
48+
}
49+
50+
int64_t ans = 0;
51+
for (int i = 0; i <= k; i++) ans = Mod(ans + f[1][i]);
52+
if (a[1][1] == -1) ans = ans * k % mod;
53+
if (a[2][n] == -1) ans = ans * k % mod;
54+
cout << ans << endl;
55+
56+
return;
57+
}
58+
59+
bool mem2;
60+
61+
int main() {
62+
ios::sync_with_stdio(false), cin.tie(nullptr);
63+
#ifdef LOCAL
64+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
65+
#endif
66+
67+
int _ = 1;
68+
cin >> _;
69+
while (_--) solve();
70+
71+
#ifdef LOCAL
72+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
73+
#endif
74+
return 0;
75+
}

0 commit comments

Comments
 (0)