QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#850437 | #8701. Border | Windy_Hill | 0 | 1ms | 7728kb | C++14 | 2.1kb | 2025-01-10 08:48:58 | 2025-01-10 08:48:59 |
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) % 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 = 0, 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;
//cout << i << " " << k1 << " " << k2 << endl;
if (s1[k2] == s2[k1])
{
int p1 = ((has1[i] - (s1[k1] - s2[k1]) * pw[i - k1] % mod) % 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) % mod;
if (p1 == p2) res[k1] = max(res[k1], i);
}
if (s1[k1] == s2[k2])
{
int p1 = ((has2[n - i + 1] - (s1[k2] - s2[k2]) * pw[n - k2] % mod) % mod + mod) % mod;
int p2 = has1[i];
if (k2 <= i) p2 = ((p2 - (s1[k2] - s2[k2]) * pw[i - k2] % mod) % 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: 23
Accepted
time: 1ms
memory: 7716kb
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: 0ms
memory: 7728kb
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: 7620kb
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: 0
Wrong Answer
time: 0ms
memory: 7692kb
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 8 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:
wrong answer 25th numbers differ - expected: '29', found: '8'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%