Skip to content

Commit fe4b7a8

Browse files
committed
Codeforces Global Round 31 (Div. 1 + Div. 2)
1 parent 3dcb64e commit fe4b7a8

8 files changed

Lines changed: 370 additions & 2 deletions

File tree

.vscode/cpp.code-snippets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
" cerr << \"Time Cost: \" << clock() * 1000. / CLOCKS_PER_SEC << \"MS\" << endl;",
3232
"#endif",
3333
" return 0;",
34-
"}"
34+
"}",
35+
""
3536
]
3637
},
3738
"TopCoder": {

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"resmon.show.cpufreq": false,
4444
"resmon.updatefrequencyms": 500,
4545
"task.quickOpen.skip": false,
46-
"terminal.integrated.defaultProfile.windows": "PowerShell",
4746
"workbench.colorTheme": "Material Theme Darker High Contrast",
4847
"workbench.iconTheme": "material-icon-theme",
4948
"workbench.list.smoothScrolling": true,

Codeforces/2180A.cpp

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

Codeforces/2180B.cpp

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

Codeforces/2180C.cpp

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

Codeforces/2180D.cpp

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

Codeforces/2180E.cpp

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

Codeforces/2180F1.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* @file 2180F1.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-12-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+
#define mod 1'000'000'007
21+
22+
int64_t qpow(int64_t a, int64_t x) {
23+
int64_t ans = 1;
24+
while (x) {
25+
if (x & 1) ans = ans * a % mod;
26+
a = a * a % mod, x >>= 1;
27+
}
28+
return ans;
29+
}
30+
int64_t inv(int64_t a) { return qpow(a, mod - 2); }
31+
32+
const int64_t frac14 = inv(4), frac34 = 3 * inv(4) % mod;
33+
34+
int64_t Mod(int64_t x) { return x >= mod ? x - mod : x; }
35+
int64_t Add(int &x, int64_t y) { return x = Mod(x + y); }
36+
37+
int f[maxn][maxn][2][2], g[maxn][maxn];
38+
39+
void solve(void) {
40+
int n, m;
41+
cin >> n >> m;
42+
cout << qpow(4, (n + 1) * (m + 1)) * g[n][m] % mod << endl;
43+
return;
44+
}
45+
46+
bool mem2;
47+
48+
int main() {
49+
ios::sync_with_stdio(false), cin.tie(nullptr);
50+
#ifdef LOCAL
51+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
52+
#endif
53+
54+
for (int x = 0; x < 2; x++)
55+
for (int y = 0; y < 2; y++) f[1][1][x][y] = (x ? frac14 : frac34) * (y ? frac14 : frac34) % mod;
56+
57+
for (int i = 1; i + 1 < maxn; i++)
58+
for (int j = 1; j + 1 < maxn; j++)
59+
for (int u = 0; u < 2; u++)
60+
for (int l = 0; l < 2; l++)
61+
for (int t = 0; t < 4; t++) {
62+
int64_t v = f[i][j][u][l] * frac14 % mod;
63+
bool U = u || (t == 0), L = l || (t == 1), D = (t == 2), R = (t == 3);
64+
if (!L) {
65+
Add(f[i + 1][j][D][0], v * frac34 % mod);
66+
Add(f[i + 1][j][D][1], v * frac14 % mod);
67+
} else if (!U) {
68+
Add(f[i][j + 1][0][R], v * frac34 % mod);
69+
Add(f[i][j + 1][1][R], v * frac14 % mod);
70+
} else
71+
Add(g[i][j], v);
72+
}
73+
74+
for (int i = 1; i < maxn; i++)
75+
for (int j = 1; j < maxn; j++) Add(g[i][j], g[i][j - 1]);
76+
for (int i = 1; i < maxn; i++)
77+
for (int j = 1; j < maxn; j++) Add(g[i][j], g[i - 1][j]);
78+
79+
int _ = 1;
80+
cin >> _;
81+
while (_--) solve();
82+
83+
#ifdef LOCAL
84+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
85+
#endif
86+
return 0;
87+
}

0 commit comments

Comments
 (0)