QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#443903 | #8521. Pattern Search II | ucup-team3890# | WA | 1ms | 5836kb | C++14 | 1.2kb | 2024-06-15 16:48:10 | 2024-06-15 16:48:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int _ = 1.5e5 + 10;
struct node {
int pos;
int len;
} f[_][30], g[_][30];
int n, ans = 998244353;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string str;
cin >> str;
n = str.length();
for (int i = 1; i <= n; i++) {
if (str[i-1] == 'a') {
f[i][0] = ((node){i + 1, 1});
g[i][0] = ((node){i - 1, 1});
f[i][1] = ((node){i, 1});
g[i][1] = ((node){i, 1});
} else {
f[i][0] = ((node){i, 1});
g[i][0] = ((node){i, 1});
f[i][1] = ((node){i + 1, 1});
g[i][1] = ((node){i - 1, 1});
}
}
for (int k = 2; k <= 29; k++) {
for (int i = 1; i <= n; i++) {
if (f[i][k-2].pos == 1) {
f[i][k] = f[i][k-2];
} else {
f[i][k] = f[f[i][k-2].pos-1][k-1];
f[i][k].len += f[i][k-2].len;
}
if (g[i][k-1].pos == n) {
g[i][k] = g[i][k-1];
} else {
g[i][k] = g[g[i][k-1].pos+1][k-2];
g[i][k].len += g[i][k-1].len;
}
}
}
for (int k = 1; k <= 29; k++) {
for (int i = 1; i < n; i++) {
if (f[i][k].pos == 1 && g[i+1][k-1].pos == n) {
ans = min(ans, f[i][k].len + g[i+1][k-1].len);
}
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5588kb
input:
aabbaab
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5836kb
input:
a
output:
998244353
result:
wrong answer 1st numbers differ - expected: '1', found: '998244353'