QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#850077 | #8701. Border | Windy_Hill | 0 | 2ms | 7720kb | C++14 | 2.0kb | 2025-01-09 20:10:49 | 2025-01-09 20:10:52 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2000010;
const int mod = 1e9 + 7;
const int base = 131;
string s1, s2;
int top, st[N];
int n, pw[N], res[N];
int has1[N], has2[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> s1 >> s2; n = s1.size();
s1 = " " + s1; s2 = " " + s2; pw[0] = 1;
for (int i = 1; i <= n; i ++ ) pw[i] = pw[i - 1] * base % mod;
for (int i = 1; i <= n; i ++ ) has1[i] = (has1[i - 1] * base + s1[i]) % mod;
for (int i = n; i >= 1; i -- ) has2[i] = (has2[i + 1] + s1[i] * pw[n - i]) % mod;
for (int i = 1; i <= n; i ++ )
if (has1[i] == has2[n - i + 1])
st[ ++ top] = i;
for (int i = 1; i <= n; i ++ )
{
int l = 1, r = i;
while (l < r)
{
int mid = (l + r) / 2;
int t1 = has1[mid] * pw[i - mid];
int t2 = has2[n - i + 1] - has2[n - i + mid + 1];
if (t1 == t2) l = mid + 1;
else r = mid;
}
int k1 = l, k2 = n - i + l;
if (s2[k1] == s1[k2])
{
int p1 = ((has1[i] - (s1[k1] - s2[k1]) * pw[i - k1]) % mod + mod) % mod;
int p2 = has2[n - i + 1];
if (n - i + 1 <= k1) p2 = ((p2 - (s1[k1] - s2[k1]) * pw[n - k1]) % mod + mod) % mod;
if (p1 == p2) res[k1] = max(res[k1], i);
}
if (s1[k2] == s2[k1])
{
int p1 = ((has2[n - i + 1] - (s1[k2] - s2[k2]) * pw[n - k2]) % mod + mod) % mod;
int p2 = has1[i];
if (k2 <= i) p2 = ((p2 - (s1[k2] - s2[k2]) * pw[i - k2]) % mod + mod) % mod;
if (p1 == p2) res[k2] = max(res[k2], i);
}
}
int p = 0;
for (int i = 1; i <= n; i ++ )
{
int k = min(i, n - i + 1);
while (st[p + 1] < k && p < top) p ++ ;
while (st[p] >= k && p > 0) p -- ;
res[i] = max(res[i], st[p]);
cout << res[i] << "\n";
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 7720kb
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 0 0 0
result:
wrong answer 43rd numbers differ - expected: '3', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%