Skip to content

Commit 5b68d72

Browse files
committed
2023 Jiangsu Collegiate Programming Contest, 2023 National Invitational of CCPC (Hunan), The 13th Xiangtan Collegiate Programming Contest
1 parent 1ac5947 commit 5b68d72

9 files changed

Lines changed: 559 additions & 0 deletions

File tree

Codeforces Gym/104396A.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @file 104396A.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-24
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+
string s;
23+
cin >> s;
24+
25+
int rest = 1;
26+
for (int i = 0; i < 100; i++) rest = rest * 10 % 26;
27+
28+
while (m > (int)s.size() / 2) {
29+
string tl = s.substr(0, s.size() / 2), tc = s, tr = s.substr(s.size() / 2);
30+
for (char& c : tr) c = (c - 'a' + 1) % 26 + 'a';
31+
s = tl + tc + tr, rest = (rest + 25) % 26;
32+
}
33+
for (size_t i = s.size() - m; i < s.size(); i++) cout << char((s[i] - 'a' + rest) % 26 + 'a');
34+
cout << 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+
while (_--) solve();
48+
49+
#ifdef LOCAL
50+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
51+
#endif
52+
return 0;
53+
}

Codeforces Gym/104396E.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* @file 104396E.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-24
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 1'000'000'007
21+
22+
using pii = pair<int, int>;
23+
24+
int64_t qpow(int64_t a, int64_t x) {
25+
int64_t ans = 1;
26+
while (x) {
27+
if (x & 1) ans = ans * a % mod;
28+
a = a * a % mod, x >>= 1;
29+
}
30+
return ans;
31+
}
32+
int64_t inv(int64_t a) { return qpow(a, mod - 2); }
33+
34+
int64_t fac[maxn], ifac[maxn], iv[maxn];
35+
36+
int64_t C(int n, int m) { return n < m ? 0 : fac[n] * ifac[m] % mod * ifac[n - m] % mod; }
37+
38+
void solve(void) {
39+
int x, k;
40+
cin >> x >> k;
41+
42+
vector<int> vals;
43+
for (int i = 1; i * i <= x; i++) {
44+
if (x % i) continue;
45+
vals.push_back(i);
46+
if (i * i < x) vals.push_back(x / i);
47+
}
48+
sort(vals.begin(), vals.end()), vals.pop_back();
49+
50+
int64_t ans = 0;
51+
for (auto G : vals) {
52+
int L = x / G - 1;
53+
54+
vector<int> rec;
55+
for (int i = 2; i * i <= L; i++) {
56+
if (L % i) continue;
57+
int cnt = 1;
58+
while (L % i == 0) L /= i, cnt++;
59+
rec.push_back(cnt);
60+
}
61+
if (L > 1) rec.push_back(2);
62+
63+
int m = rec.size();
64+
65+
for (int S = 0; S < (1 << m); S++)
66+
for (int T = 0; T < (1 << m); T++) {
67+
int prod = 1, coef = ((__builtin_popcount(S) ^ __builtin_popcount(T)) & 1) ? -1 : +1;
68+
for (int i = 0; i < m; i++) prod *= rec[i] - (S >> i & 1) - (T >> i & 1);
69+
ans = (ans + mod + coef * C(prod, k)) % mod;
70+
}
71+
cerr << L << " " << ans << endl;
72+
}
73+
74+
cout << ans << endl;
75+
76+
return;
77+
}
78+
79+
bool mem2;
80+
81+
int main() {
82+
ios::sync_with_stdio(false), cin.tie(nullptr);
83+
#ifdef LOCAL
84+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
85+
#endif
86+
87+
fac[0] = ifac[0] = iv[0] = 1;
88+
for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod;
89+
ifac[maxn - 1] = inv(fac[maxn - 1]);
90+
for (int i = maxn - 2; i; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
91+
for (int i = 1; i < maxn; i++) iv[i] = ifac[i] * fac[i - 1] % mod;
92+
93+
int _ = 1;
94+
while (_--) solve();
95+
96+
#ifdef LOCAL
97+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
98+
#endif
99+
return 0;
100+
}

Codeforces Gym/104396F.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @file 104396F.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-24
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+
21+
double f[maxn];
22+
23+
void solve(void) {
24+
int A, B;
25+
double P, Q;
26+
cin >> A >> B >> P >> Q, P /= 100, Q /= 100;
27+
28+
for (int i = B; i <= A; i++)
29+
f[i] = max(f[i - B] + 1 + P, B == 1 ? f[i - 1] + 1 / (1 - Q) : 1 + f[i - B] * (1 - Q) + f[i - B + 1] * Q);
30+
31+
cout << fixed << setprecision(15) << f[A] << 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+
while (_--) solve();
46+
47+
#ifdef LOCAL
48+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
49+
#endif
50+
return 0;
51+
}

Codeforces Gym/104396G.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* @file 104396G.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-24
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+
using pii = pair<int, int>;
20+
21+
void solve(void) {
22+
int n;
23+
int64_t C;
24+
cin >> n >> C;
25+
26+
vector<pii> dl, dr;
27+
for (int i = 1, x, y; i <= n; i++) {
28+
cin >> x >> y;
29+
if (x < y) dr.emplace_back(x, +1), dr.emplace_back(y, -1);
30+
if (x > y) dl.emplace_back(y, +1), dl.emplace_back(x, -1);
31+
}
32+
33+
sort(dl.begin(), dl.end()), sort(dr.begin(), dr.end());
34+
35+
vector<pii> rec;
36+
rec.emplace_back(-1e9 - 1, 0);
37+
int lv = 0, rv = 0;
38+
for (auto lp = dl.begin(), rp = dr.begin(); lp != dl.end() || rp != dr.end();) {
39+
int x = min(lp == dl.end() ? INT_MAX : lp->first, rp == dr.end() ? INT_MAX : rp->first);
40+
while (lp != dl.end() && lp->first == x) lv += (lp++)->second;
41+
while (rp != dr.end() && rp->first == x) rv += (rp++)->second;
42+
int v = max({int(lp != dl.end() || rp != dr.end()), lv, rv});
43+
if (v != rec.back().second) rec.emplace_back(x, v);
44+
}
45+
46+
stack<int> S;
47+
S.push(0);
48+
int64_t ans = 0;
49+
for (int i = 1; i + 1 < (int)rec.size(); i++) {
50+
int len = rec[i + 1].first - rec[i].first;
51+
ans += (int64_t)len * 2 * rec[i].second + abs(rec[S.top()].second - rec[i].second) * C;
52+
while (S.size() > 1 && rec[S.top()].second < rec[i].second && rec[i].first - rec[S.top()].first < C) {
53+
auto t = S.top();
54+
S.pop();
55+
int delt = min(rec[S.top()].second, rec[i].second) - rec[t].second;
56+
ans -= delt * 2 * (C - (rec[i].first - rec[t].first)), rec[t].second += delt;
57+
if (rec[S.top()].second > rec[t].second) S.push(t);
58+
}
59+
if (rec[S.top()].second < rec[i].second)
60+
while (!S.empty()) S.pop();
61+
if (S.empty() || rec[S.top()].second > rec[i].second) S.push(i);
62+
}
63+
cout << ans + rec[S.top()].second * C << endl;
64+
65+
return;
66+
}
67+
68+
bool mem2;
69+
70+
int main() {
71+
ios::sync_with_stdio(false), cin.tie(nullptr);
72+
#ifdef LOCAL
73+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
74+
#endif
75+
76+
int _ = 1;
77+
while (_--) solve();
78+
79+
#ifdef LOCAL
80+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
81+
#endif
82+
return 0;
83+
}

Codeforces Gym/104396H.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @file 104396H.cpp
3+
* @author Macesuted (i@macesuted.moe)
4+
* @date 2025-07-24
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+
string S, T;
26+
cin >> n >> S >> T;
27+
for (int i = 1; i <= n; i++) a[i] = (T[i - 1] - S[i - 1] + 26) % 26;
28+
a[0] = 0;
29+
for (int i = n; i >= 1; i--) a[i] = (a[i] - a[i - 1] + 26) % 26;
30+
int ans = 0;
31+
for (int i = 1; i <= n; i++) ans += (a[i] > 0);
32+
cout << ans << 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+
while (_--) solve();
47+
48+
#ifdef LOCAL
49+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
50+
#endif
51+
return 0;
52+
}

Codeforces Gym/104396I.cpp

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

0 commit comments

Comments
 (0)