QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#847236#8701. BorderLUHCUH0 4ms214764kbC++142.0kb2025-01-07 19:18:502025-01-07 19:18:50

Judging History

你现在查看的是最新测评结果

  • [2025-01-07 19:18:50]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:214764kb
  • [2025-01-07 19:18:50]
  • 提交

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 (t[x - l1] != s[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); st.insert(cp[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: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 214764kb

input:

cbaababaabacbaababaabacbaabacbaababaabacbaaba
dabbababbabaabbafabbgbaabfebaabzababbayaabcac

output:

0
1
2
3
3
5
6
6
6
6
6
11
11
11
11
11
11
17
17
17
17
17
22
17
17
17
17
17
11
11
11
11
11
11
6
6
6
6
6
5
3
3
2
1
0

result:

wrong answer 2nd numbers differ - expected: '0', found: '1'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%