Skip to content

Commit 401b86e

Browse files
committed
Good Bye 2025
1 parent fe4b7a8 commit 401b86e

File tree

6 files changed

+388
-0
lines changed

6 files changed

+388
-0
lines changed

Codeforces/2178A.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @file 2178A.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-12-27
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+
string s;
21+
cin >> s;
22+
23+
int cntN = 0;
24+
for (auto c : s) cntN += (c == 'N');
25+
26+
int cntY = s.size() - cntN;
27+
28+
cout << (cntY <= 1 ? "YES" : "NO") << endl;
29+
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/2178B.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @file 2178B.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-12-27
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+
string s;
21+
cin >> s;
22+
23+
int f[2] = {int(1e9), s[0] == 'u'};
24+
25+
for (auto c : s.substr(1)) {
26+
if (c == 's')
27+
f[1] = min(f[0], f[1]), f[0] = 1e9;
28+
else
29+
tie(f[0], f[1]) = make_pair(f[1], 1 + min(f[0], f[1]));
30+
}
31+
32+
cout << f[1] << endl;
33+
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+
}

Codeforces/2178C.cpp

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

Codeforces/2178D.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @file 2178D.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-12-27
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];
24+
int id[maxn];
25+
26+
void solve(void) {
27+
int n, m;
28+
cin >> n >> m;
29+
for (int i = 1; i <= n; i++) cin >> a[i];
30+
31+
if (m * 2 > n) return cout << -1 << endl, void();
32+
33+
for (int i = 1; i <= n; i++) id[i] = i;
34+
sort(id + 1, id + n + 1, [&](int x, int y) { return a[x] < a[y]; });
35+
sort(a + 1, a + n + 1);
36+
37+
vector<pii> ans;
38+
39+
if (m > 0) {
40+
for (int i = 1; i < m; i++) ans.emplace_back(n - i + 1, i);
41+
for (int i = m; i + 1 < n - m + 1; i++) ans.emplace_back(i, i + 1);
42+
ans.emplace_back(n - m + 1, n - m);
43+
} else {
44+
int h = a[n], p = 1;
45+
while (a[n - 1] < h && p < n - 1) ans.emplace_back(p, n), h -= a[p++];
46+
if (a[n - 1] < h) return cout << -1 << endl, void();
47+
while (p < n) ans.emplace_back(p, p + 1), p++;
48+
}
49+
50+
cout << ans.size() << endl;
51+
for (auto [x, y] : ans) cout << id[x] << ' ' << id[y] << 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+
int _ = 1;
65+
cin >> _;
66+
while (_--) solve();
67+
68+
#ifdef LOCAL
69+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
70+
#endif
71+
return 0;
72+
}

Codeforces/2178E.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @file 2178E.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-12-27
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
bool mem1;
14+
15+
int lg2(int64_t x) {
16+
int cnt = 0;
17+
while (!(x & 1)) x >>= 1, cnt++;
18+
return cnt;
19+
}
20+
21+
int64_t query(int l, int r) {
22+
cout << "? " << l << ' ' << r << endl;
23+
int64_t ret;
24+
cin >> ret;
25+
return ret;
26+
}
27+
28+
int solve(int l, int r, int k) {
29+
if (l == r) return k;
30+
31+
int64_t tar = (int64_t)1 << (k - 1);
32+
33+
int xl = l, xr = r;
34+
while (xl + 1 < xr) {
35+
int mid = (xl + xr) >> 1;
36+
(query(l, mid) <= tar ? xl : xr) = mid;
37+
}
38+
39+
return xr - l <= r - xl ? solve(l, xl, k - 1) : solve(xr, r, k - 1);
40+
}
41+
42+
void solve(void) {
43+
int n;
44+
cin >> n;
45+
46+
int k = solve(1, n, lg2(query(1, n)));
47+
48+
cout << "! " << ((int64_t)1 << k) << endl;
49+
50+
return;
51+
}
52+
53+
bool mem2;
54+
55+
int main() {
56+
ios::sync_with_stdio(false), cin.tie(nullptr);
57+
#ifdef LOCAL
58+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
59+
#endif
60+
61+
int _ = 1;
62+
cin >> _;
63+
while (_--) solve();
64+
65+
#ifdef LOCAL
66+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
67+
#endif
68+
return 0;
69+
}

Codeforces/2178F.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @file 2178F.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-12-28
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 998244353
21+
22+
vector<vector<int>> graph;
23+
int siz[maxn];
24+
25+
int64_t qpow(int64_t a, int64_t x) {
26+
int64_t ans = 1;
27+
while (x) {
28+
if (x & 1) ans = ans * a % mod;
29+
a = a * a % mod, x >>= 1;
30+
}
31+
return ans;
32+
}
33+
int64_t inv(int64_t a) { return qpow(a, mod - 2); }
34+
35+
void dfs(int p, int pre = -1) {
36+
siz[p] = 1;
37+
for (auto q : graph[p])
38+
if (q != pre) dfs(q, p), siz[p] += (siz[q] & 1) ? siz[q] : 0;
39+
return;
40+
}
41+
42+
void solve(void) {
43+
int n;
44+
cin >> n;
45+
graph.clear(), graph.resize(n + 1);
46+
for (int i = 1, x, y; i < n; i++) cin >> x >> y, graph[x].push_back(y), graph[y].push_back(x);
47+
48+
dfs(1);
49+
50+
vector<int> S;
51+
for (int i = 2; i <= n; i++)
52+
if (!(siz[i] & 1)) S.push_back(siz[i]);
53+
54+
if (S.empty()) return cout << 1 << endl, void();
55+
56+
int64_t ans = 0, mul = 1;
57+
for (auto s : S) mul = mul * s % mod;
58+
mul = mul * mul % mod * siz[1] % mod;
59+
60+
for (auto s : S) ans = (ans + mul * inv(s)) % mod;
61+
62+
for (int i = 1; i < (int)S.size(); i++) ans = ans * i % mod;
63+
64+
cout << ans << endl;
65+
66+
return;
67+
}
68+
69+
bool mem2;
70+
71+
int main() {
72+
ios::sync_with_stdio(false), cin.tie(nullptr);
73+
#ifdef LOCAL
74+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
75+
#endif
76+
77+
int _ = 1;
78+
cin >> _;
79+
while (_--) solve();
80+
81+
#ifdef LOCAL
82+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
83+
#endif
84+
return 0;
85+
}

0 commit comments

Comments
 (0)