Skip to content

Commit 829a6e0

Browse files
committed
QOJ: The 3rd Universal Cup. Stage 34: Aobayama
1 parent 247f07d commit 829a6e0

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

.vscode/tasks.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"'${fileBasename}'",
1313
"-o",
1414
"'${fileBasenameNoExtension}.exe'",
15+
"-std=c++23",
1516
"-Wall",
1617
"-Wextra",
1718
"-O2",
@@ -71,6 +72,7 @@
7172
"-o",
7273
"'${fileBasenameNoExtension}.exe'",
7374
"-glldb",
75+
"-std=c++23",
7476
"-Wall",
7577
"-Wextra",
7678
"-O2",

QOJ/10325.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @file 10325.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2025-04-17
5+
*
6+
* @copyright Copyright (c) 2025
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#define endl '\n'
14+
15+
#define maxn 1000005
16+
17+
int pre[maxn];
18+
19+
void solve(void) {
20+
int n;
21+
cin >> n;
22+
string s;
23+
cin >> s, s = ' ' + s;
24+
25+
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (s[i] == '1');
26+
27+
int xp = 0, xr = -1, rest1 = 2;
28+
for (int l = 1, r; l <= n; l = r + 1) {
29+
r = l;
30+
while (r + 1 <= n && s[l] == s[r + 1]) r++;
31+
if (s[l] == '0') {
32+
if ((r - l + 1) * 2 > (n - pre[n])) xp = l, xr = r;
33+
rest1 = min(rest1, (pre[l - 1] > 0) + (pre[n] - pre[r] > 0));
34+
}
35+
}
36+
37+
if (xp == 0) {
38+
if ((n - pre[n]) % 2 == 0) return cout << (n - pre[n]) / 2 + pre[n] - 1 << endl, void();
39+
return cout << (n - pre[n]) / 2 + pre[n] - rest1 << endl, void();
40+
}
41+
42+
cout << (n - pre[n] - (xr - xp + 1)) + pre[n] - (pre[xp - 1] > 0) - (pre[n] - pre[xr] > 0) << endl;
43+
44+
return;
45+
}
46+
47+
int main() {
48+
ios::sync_with_stdio(false), cin.tie(nullptr);
49+
50+
int _ = 1;
51+
cin >> _;
52+
while (_--) solve();
53+
54+
return 0;
55+
}

QOJ/10332.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define endl '\n'
5+
6+
void solve(void) {
7+
int64_t s, t;
8+
cin >> s >> t;
9+
10+
int64_t v = sqrt(s + t);
11+
if (v * v == s + t) return cout << "1 " << t << endl, void();
12+
13+
if (s == t) {
14+
v = sqrt(s) + 1;
15+
return cout << "2 " << v * v - s << ' ' << t << endl, void();
16+
}
17+
18+
{
19+
int64_t delt = abs(s - t), base = 1;
20+
if (delt % 2 == 1) {
21+
int64_t i = delt / 2;
22+
if (s > t && (i + 1) * (i + 1) * base > s)
23+
return cout << "2 " << (i + 1) * (i + 1) * base - s << ' ' << t << endl, void();
24+
if (s < t && i * i * base > s) return cout << "2 " << i * i * base - s << ' ' << t << endl, void();
25+
} else if (delt % 4 == 0) {
26+
int64_t q = delt / 4;
27+
if (!(q < 1 || (q - 1) * (q - 1) < min(s, t) || (q + 1) * (q + 1) < max(s, t)))
28+
return cout << "2 " << (q - 1) * (q - 1) - min(s, t) << ' ' << t << endl, void();
29+
}
30+
}
31+
32+
int64_t sum = s + t;
33+
int64_t x = sqrt(sum + 2 * sqrt(sum) + 1) + 1;
34+
while (!((x * x - sum) & 1)) x++;
35+
int64_t y = (x * x - sum) / 2;
36+
cout << "3 " << x * x - s << ' ' << y * y - t << ' ' << t << endl;
37+
38+
return;
39+
}
40+
41+
int main() {
42+
ios::sync_with_stdio(false), cin.tie(nullptr);
43+
44+
int _ = 1;
45+
cin >> _;
46+
while (_--) solve();
47+
48+
return 0;
49+
}

compile_flags.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-xc++
22
-Wall
33
-Wextra
4-
-DLOCAL
4+
-DLOCAL
5+
-std=c++23

0 commit comments

Comments
 (0)