Skip to content

Commit 6786214

Browse files
committed
Codeforces: Round 1004 (Div. 1)
1 parent 38bb322 commit 6786214

File tree

4 files changed

+277
-0
lines changed

4 files changed

+277
-0
lines changed

Codeforces/2066A.cpp

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* @file 2066A.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-02-11
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], pos[maxn];
22+
bool vis[maxn];
23+
24+
int query(int x, int y) {
25+
cout << "? " << x << ' ' << y << endl;
26+
int v;
27+
cin >> v;
28+
return v;
29+
}
30+
31+
void solve(void) {
32+
int n;
33+
cin >> n;
34+
for (int i = 1; i <= n; i++) cin >> a[i], vis[i] = false, pos[a[i]] = i;
35+
for (int i = 1; i <= n; i++) vis[a[i]] = true;
36+
37+
int p = 0;
38+
for (int i = 1; i <= n; i++)
39+
if (!vis[i]) p = i;
40+
41+
if (p) {
42+
int v = query(p, p % n + 1);
43+
return cout << "! " << "AB"[v > 0] << endl, void();
44+
}
45+
46+
int v = query(pos[1], pos[n]), w = query(pos[n], pos[1]);
47+
cout << "! " << "AB"[v >= n - 1 && w >= n - 1] << endl;
48+
return;
49+
}
50+
51+
bool mem2;
52+
53+
int main() {
54+
#ifdef LOCAL
55+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
56+
#endif
57+
58+
int _ = 1;
59+
cin >> _;
60+
while (_--) solve();
61+
62+
#ifdef LOCAL
63+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
64+
#endif
65+
return 0;
66+
}

Codeforces/2066B.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* @file 2066B.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-02-11
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], mv[maxn];
22+
23+
void solve(void) {
24+
int n;
25+
cin >> n;
26+
int cnt0 = 0;
27+
for (int i = 1; i <= n; i++) cin >> a[i], cnt0 += (a[i] == 0);
28+
29+
if (!cnt0) return cout << n << endl, void();
30+
31+
bool met = false;
32+
int m = 0;
33+
for (int i = 1; i <= n; i++)
34+
if (a[i] || !met) b[++m] = a[i], met |= (a[i] == 0);
35+
36+
bool chk = true;
37+
unordered_set<int> S;
38+
mv[0] = INT_MAX;
39+
for (int i = 1; i <= m; i++) mv[i] = min(mv[i - 1], b[i]);
40+
for (int i = m, mex = 0; i > 1 && chk; i--) {
41+
S.insert(b[i]);
42+
while (S.count(mex)) mex++;
43+
if (mv[i - 1] < mex) chk = false;
44+
}
45+
46+
cout << (chk ? m : m - 1) << endl;
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/2066C.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @file 2066C.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-02-11
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+
#define mod 1'000'000'007
21+
22+
int a[maxn], pre[maxn];
23+
24+
int Mod(int x) { return x >= mod ? x - mod : x; }
25+
26+
void solve(void) {
27+
int n;
28+
cin >> n;
29+
for (int i = 1; i <= n; i++) cin >> a[i], pre[i] = pre[i - 1] ^ a[i];
30+
31+
unordered_map<int, int> f;
32+
f[0] = 1;
33+
for (int i = 1; i <= n; i++) {
34+
int det = 0;
35+
if (f.count(pre[i - 1])) det = Mod(det + Mod(2 * f[pre[i - 1]]));
36+
if (f.count(pre[i])) det = Mod(det + Mod(2 * f[pre[i]]));
37+
if (det) f[pre[i - 1]] = Mod(f[pre[i - 1]] + det);
38+
}
39+
40+
int ans = 0;
41+
for (auto [i, v] : f) ans = Mod(ans + v);
42+
43+
cout << ans << endl;
44+
45+
return;
46+
}
47+
48+
bool mem2;
49+
50+
int main() {
51+
ios::sync_with_stdio(false), cin.tie(nullptr);
52+
#ifdef LOCAL
53+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
54+
#endif
55+
56+
int _ = 1;
57+
cin >> _;
58+
while (_--) solve();
59+
60+
#ifdef LOCAL
61+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
62+
#endif
63+
return 0;
64+
}

Codeforces/2066D1.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @file 2066D1.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-02-11
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 105
20+
#define maxm 10005
21+
#define mod 1'000'000'007
22+
23+
int a[maxm], f[maxn][maxm];
24+
int64_t fac[maxm], ifac[maxm];
25+
26+
int64_t qpow(int64_t a, int64_t x) {
27+
int64_t ans = 1;
28+
while (x) {
29+
if (x & 1) ans = ans * a % mod;
30+
a = a * a % mod, x >>= 1;
31+
}
32+
return ans;
33+
}
34+
int64_t inv(int64_t a) { return qpow(a, mod - 2); }
35+
36+
int Mod(int x) { return x >= mod ? x - mod : x; }
37+
38+
int64_t C(int n, int m) { return fac[n] * ifac[m] % mod * ifac[n - m] % mod; }
39+
40+
void solve(void) {
41+
int n, c, m;
42+
cin >> n >> c >> m;
43+
for (int i = 1; i <= m; i++) cin >> a[i];
44+
45+
for (int i = 1; i <= n; i++)
46+
for (int j = 1; j <= m; j++) f[i][j] = 0;
47+
48+
f[n][c] = 1;
49+
for (int i = n - 1; i >= 1; i--)
50+
for (int j = c; j <= m; j++)
51+
if (f[i + 1][j])
52+
for (int k = 0; k <= min(m - j, c); k++) f[i][j + k] = (f[i][j + k] + f[i + 1][j] * C(c, k)) % mod;
53+
54+
cout << f[1][m] << 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+
fac[0] = ifac[0] = 1;
68+
for (int i = 1; i < maxm; i++) fac[i] = fac[i - 1] * i % mod;
69+
ifac[maxm - 1] = inv(fac[maxm - 1]);
70+
for (int i = maxm - 2; i; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
71+
72+
int _ = 1;
73+
cin >> _;
74+
while (_--) solve();
75+
76+
#ifdef LOCAL
77+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
78+
#endif
79+
return 0;
80+
}

0 commit comments

Comments
 (0)