QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#847251 | #8701. Border | LUHCUH | 23 | 16ms | 218664kb | C++14 | 2.0kb | 2025-01-07 19:24:51 | 2025-01-07 19:24:51 |
Judging History
answer
#include <set>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 2000200;
typedef unsigned long long ull;
char s[N], t[N];
ull h[N], p[N];
ull H(int l, int r) { return (h[r] - (l >= 1 ? h[l - 1] : 0) * p[r - l + 1]); }
int lcp(int x, int y)
{
int l = 0, r = min(x, y), ans = -1;
while (l <= r)
{
int m = l + r >> 1;
if (H(x - m + 1, x) == H(y - m + 1, y))l = m + 1, ans = m;
else r = m - 1;
}
return ans;
}
const int C = 26;
int cp[N], len[N][C], ans[N];
int lcp(int c, int x, int y)
{
if (x > y)swap(x, y);
if (c <= x)
{
int l1 = x - c, l2 = y - c, res;
res = lcp(x, y);
if (res < l1)return res;
if (t[x - l1] != s[y - l1])return l1;
res = l1 + 1 + lcp(x - l1 - 1, y - l1 - 1);
if (res < l2)return res;
if (s[x - l2] != t[y - l2])return l2;
res = l2 + 1 + lcp(x - l2 - 1, y - l2 - 1);
return res;
}
else
{
int l1 = y - c, res;
res = lcp(x, y);
if (res < l1)return res;
if (s[x - l1] != t[y - l1])return l1;
return l1 + 1 + lcp(x - l1 - 1, y - l1 - 1);
}
}
int main()
{
memset(len, -1, sizeof len);
cin >> s + 1 >> t + 1;int n = strlen(s + 1);
h[0] = s[0];p[0] = 1;
for (int i = 1;i <= n + 1;i++)p[i] = p[i - 1] * 131;
for (int i = 1;i <= n + 1;i++)h[i] = h[i - 1] * 131 + s[i];
set<int> st;
for (int i = 1;i < n;i++)
{
cp[i] = lcp(i, n); if (i == cp[i])st.insert(i);if (i == cp[i])continue;
if (lcp(n - cp[i], i, n) == i)ans[n - cp[i]] = max(ans[n - cp[i]], i);
if (lcp(i - cp[i], i, n) == i)ans[i - cp[i]] = max(ans[n - cp[i]], i);
}
st.insert(0x3f3f3f3f);
for (int i = 1;i <= n;i++)
{
int ll = min(n - i + 1, i);
auto r = st.upper_bound(ll - 1);
if (r != st.begin())ans[i] = max(ans[i], *(--r));
}
for (int i = 1;i <= n;i++)cout << ans[i] << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 23
Accepted
Test #1:
score: 23
Accepted
time: 3ms
memory: 216812kb
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: 7ms
memory: 218580kb
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: 16ms
memory: 216576kb
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: 15ms
memory: 216740kb
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: 216516kb
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: 3ms
memory: 218664kb
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: 31
Accepted
time: 7ms
memory: 216596kb
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:
ok 4623 numbers
Test #8:
score: 0
Wrong Answer
time: 0ms
memory: 216600kb
input:
gcdcbcacacacbcacdcbcacaedcbcacacacbcacdcfcacacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacagcdcbcacacacbcacdcbcacaedcbcacacacbcacdcbcacacdcbcacaedcbcacacacbcacdcbcacacdcbcacacdcbcacacacbcacdcbcacaedcbcaca...
output:
187 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 2931st numbers differ - expected: '508', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%