QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#934799 | #9614. 分治 | Str_ywr | 10 | 1ms | 3712kb | C++14 | 1.5kb | 2025-03-15 09:36:33 | 2025-03-15 09:36:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
} return x * f;
}
const int N = 3e5 + 10, mod = 998244353; const ll inf = 1e18;
int n; typedef pair<ll,ll> pll;
vector<pll> f[105]; int id[N], tot;
void ck(pll &x, pll y) {
if (y > x) x = y;
}
int dfs(int x) {
if (id[x]) return id[x];
id[x] = ++tot; int nw = tot; f[nw].resize(x + 1, {-inf,-inf});
assert(tot < 100);
if (x == 1) {
f[nw][0] = {0,0}; f[nw][1] = {1,1};
return nw;
}
int ln = (x + 1) >> 1, rn = x >> 1;
int lc = dfs((x + 1) >> 1); int rc = dfs(x >> 1);
// f[nw][0] = {0,0};
for (int i = 0; i <= x; i++) {
for (int j = 0; j <= min(i, ln); j++) {
for (int k = 0; k <= rn && k + j <= i; k++) {
ll mx = max(f[lc][j].second, f[rc][k].second) + i - j - k;
ck(f[nw][i], {f[lc][j].first + f[rc][k].first + mx, mx});
}
}
} assert(f[nw][0].first == 0 && f[nw][0].second == 0);
return nw;
}
int main() {
string s; cin >> s;
for (int i = 0; i < s.size(); i++) {
n = (n << 1) | (s[i] - '0');
}
int rt = dfs(n);
ll ans = f[rt][n].first;
ans = (ans % mod + mod) % mod;
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3584kb
input:
110
output:
15
result:
ok 1 number(s): "15"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
101
output:
12
result:
ok 1 number(s): "12"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 3712kb
input:
111110
output:
180
result:
wrong answer 1st numbers differ - expected: '198', found: '180'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Runtime Error
Test #7:
score: 0
Runtime Error
input:
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%