Skip to content

Commit 2415370

Browse files
committed
AtCoder Regular Contest 203 (Div. 2)
1 parent f6df628 commit 2415370

4 files changed

Lines changed: 246 additions & 0 deletions

File tree

AtCoder/arc203_a.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @file arc203_a.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-08-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+
int64_t n, m;
21+
cin >> n >> m;
22+
cout << n * (m / 2) + (m % 2) << 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+
}

AtCoder/arc203_b.cpp

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

AtCoder/arc203_c.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* @file arc203_c.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-08-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 1000005
20+
#define mod 998244353
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+
int64_t fac[maxn], ifac[maxn];
33+
34+
int64_t binom(int n, int m) { return 0 <= m && m <= n ? fac[n] * ifac[m] % mod * ifac[n - m] % mod : 0; }
35+
36+
void solve(void) {
37+
int64_t n, m, k;
38+
cin >> n >> m >> k;
39+
40+
if (k < n + m - 2) return cout << 0 << endl, void();
41+
if (k == n + m - 2) return cout << binom(n + m - 2, n - 1) << endl, void();
42+
if (k == n + m - 1) return cout << binom(n + m - 2, n - 1) * 2 * (n - 1) % mod * (m - 1) % mod << endl, void();
43+
44+
int64_t v1 = 0;
45+
if (n >= 3) v1 = (v1 + binom(n + m - 3, m) * (m - 1) % mod * (n - 2) - binom(n + m - 3, m + 1) * m % mod * (m - 1)) % mod;
46+
if (m >= 3) v1 = (v1 + binom(n + m - 3, n) * (n - 1) % mod * (m - 2) - binom(n + m - 3, n + 1) * n % mod * (n - 1)) % mod;
47+
48+
int64_t v2 = (2 * (n - 1) * (m - 1) - 1) % mod * (n - 1) % mod * (m - 1) % mod * binom(n + m - 2, n - 1) % mod;
49+
int64_t v3 = (n + m - 3) * binom(n + m - 4, n - 2) % mod;
50+
51+
cout << ((v1 + v2 - v3) % mod + mod) % mod << endl;
52+
53+
return;
54+
}
55+
56+
bool mem2;
57+
58+
int main() {
59+
ios::sync_with_stdio(false), cin.tie(nullptr);
60+
#ifdef LOCAL
61+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
62+
#endif
63+
64+
fac[0] = ifac[0] = 1;
65+
for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod;
66+
ifac[maxn - 1] = inv(fac[maxn - 1]);
67+
for (int i = maxn - 2; i; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
68+
69+
int _ = 1;
70+
cin >> _;
71+
while (_--) solve();
72+
73+
#ifdef LOCAL
74+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
75+
#endif
76+
return 0;
77+
}

AtCoder/arc203_d.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @file arc203_d.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-08-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+
int a[maxn];
22+
23+
void solve(void) {
24+
int n;
25+
cin >> n;
26+
set<int> S[2];
27+
for (int i = 1; i <= n; i++) cin >> a[i], S[a[i]].insert(i);
28+
29+
int xcnt = 0;
30+
auto calc = [&](int p) -> bool { return p < 1 || p + 2 > n ? 0 : a[p] && !a[p + 1] && !a[p + 2]; };
31+
for (int i = 1; i <= n; i++) xcnt += calc(i);
32+
33+
auto query = [&](void) -> int {
34+
if (S[0].empty()) return n;
35+
if (S[1].empty()) return 2;
36+
37+
int x0 = xcnt, pl = *S[1].begin() - 1, pr = n - *S[1].rbegin();
38+
if (pr >= 2) x0--;
39+
if (a[1] && a[n] && !x0) return 2;
40+
int ans = x0 * 3 + 1;
41+
return min(2, pl) + ans + min(2, pr);
42+
};
43+
44+
int q;
45+
cin >> q;
46+
while (q--) {
47+
int x;
48+
cin >> x;
49+
S[a[x]].erase(x);
50+
xcnt -= calc(x - 2) + calc(x - 1) + calc(x);
51+
S[a[x] = !a[x]].insert(x);
52+
xcnt += calc(x - 2) + calc(x - 1) + calc(x);
53+
54+
cout << query() << 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+
while (_--) solve();
69+
70+
#ifdef LOCAL
71+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
72+
#endif
73+
return 0;
74+
}

0 commit comments

Comments
 (0)