QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#835492 | #8701. Border | hhoppitree | 23 | 2ms | 12068kb | C++17 | 2.0kb | 2024-12-28 12:18:37 | 2024-12-28 12:18:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5, B = 1145141;
int n;
string S, T;
int nxt[N], bd[N], pre[N], res[N];
int lcp[N], lcs[N];
unsigned long long hs[N], pw[N];
int Hash(int l, int r, int x) {
if (x < l || x > r) return hs[r] - hs[l - 1] * pw[r - l + 1];
return hs[r] - hs[l - 1] * pw[r - l + 1] + (T[x] - S[x]) * pw[r - x];
}
void check(int x, int y) {
if (Hash(1, x, y) == Hash(n - x + 1, n, y)) res[y] = max(res[y], x);
}
signed main() {
cin >> S >> T;
n = S.size(), S = ' ' + S, T = ' ' + T;
for (int i = pw[0] = 1; i <= n; ++i) {
pw[i] = pw[i - 1] * B, hs[i] = hs[i - 1] * B + S[i];
}
for (int i = 2, j = 0; i <= n; ++i) {
while (j && S[i] != S[j + 1]) j = nxt[j];
if (S[i] == S[j + 1]) ++j;
nxt[i] = j;
}
for (int i = nxt[n]; i; i = nxt[i]) bd[i] = 1, pre[i] = i;
for (int i = 1; i <= n; ++i) pre[i] = max(pre[i], pre[i - 1]);
for (int i = 2, l = 0, r = 0; i <= n; ++i) {
lcp[i] = max(min(lcp[i - l + 1], r - i + 1), 0);
while (i + lcp[i] <= n && S[1 + lcp[i]] == S[i + lcp[i]]) ++lcp[i];
if (i + lcp[i] - 1 > r) l = i, r = i + lcp[i] - 1;
}
reverse(S.begin() + 1, S.end());
for (int i = 2, l = 0, r = 0; i <= n; ++i) {
lcs[i] = max(min(lcs[i - l + 1], r - i + 1), 0);
while (i + lcs[i] <= n && S[1 + lcs[i]] == S[i + lcs[i]]) ++lcs[i];
if (i + lcs[i] - 1 > r) l = i, r = i + lcs[i] - 1;
}
reverse(lcs + 1, lcs + n + 1);
reverse(S.begin() + 1, S.end());
for (int i = 1; i < n; ++i) {
if (bd[i]) continue;
int c1 = lcp[n - i + 1], c2 = lcs[i];
check(i, c1 + 1), check(i, n - c2), check(i, i - c2), check(i, i + c1);
}
for (int i = 1; i <= n; ++i) {
if (S[i] == T[i]) printf("%d\n", nxt[i]);
else {
printf("%d\n", max(res[i], pre[min(i - 1, n - i)]));
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 23
Accepted
Test #1:
score: 23
Accepted
time: 1ms
memory: 9864kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
0 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 17 17 17 17 17 17 17 17 17 17 17 6 6 6 6 6 6 6 6 6 6 6 0 0 0 3 0 1
result:
ok 45 numbers
Test #2:
score: 23
Accepted
time: 1ms
memory: 9876kb
input:
cbaababaabacbaabadbaababaabacbaabacbaaba aabwaxjbbabtalbabcasbabibbabaabbabaabiac
output:
3 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 23 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 0 0 0 0 0 1
result:
ok 40 numbers
Test #3:
score: 23
Accepted
time: 1ms
memory: 9932kb
input:
cadaabacabacabacabaabacabacadaabacabacaba bbbbbabtbabababalalbawababababbaoababebdc
output:
2 0 4 0 0 0 0 0 0 0 0 0 0 0 0 15 15 15 15 15 15 15 15 15 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 4 1
result:
ok 41 numbers
Test #4:
score: 23
Accepted
time: 0ms
memory: 9964kb
input:
dabacbaadcbaadabacbaadabecbaadcbaadabacbaadabacbaa ababaabbyaarbabfbvdbuaoaaaabbaaabbababaabbababqadd
output:
2 0 0 0 0 0 0 0 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 29 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 2 1
result:
ok 50 numbers
Test #5:
score: 23
Accepted
time: 0ms
memory: 5780kb
input:
edacbcacacbcaecbcacacbcadacbcacacbca sabaaabtbaaabaaalblbawaeabaaababoaae
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0 0 0 0 0 1
result:
ok 36 numbers
Test #6:
score: 23
Accepted
time: 1ms
memory: 10156kb
input:
cbaababaabacbaabacbaabdbaabacbaabacbaaba aabbababbaoaabbxbaabbaqabbabltbpagaabcac
output:
3 0 0 0 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 0 0 0 3 0 1
result:
ok 40 numbers
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #7:
score: 0
Wrong Answer
time: 2ms
memory: 12068kb
input:
abacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacababacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacadcabbacabbacaecabbacabacabbacabbacabcabbacabbacadcabbacabbacabcabbacababacadcabbacabbacabcabbacabacabbacabbacabcabbacabbacad...
output:
27 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75...
result:
wrong answer 3139th numbers differ - expected: '717', found: '148'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%