QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#850486 | #8701. Border | __zyx__ | 0 | 0ms | 7728kb | C++14 | 1.4kb | 2025-01-10 09:23:58 | 2025-01-10 09:24:00 |
answer
#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
const int N = 2e6 + 5;
const int base = 31;
char s[N], t[N];
int ans[N], hsh[N], p[N];
int cal(int l, int r) {
return hsh[r] - hsh[l - 1] * p[r - l + 1];
}
signed main() {
cin >> s + 1 >> t + 1;
int n = strlen(s + 1), mx = 0; p[0] = 1;
for (int i = 1; i <= n; i++) {
hsh[i] = hsh[i - 1] * base + s[i] - 'a' + 1;
p[i] = p[i - 1] * base;
}
for (int i = 1; i < n; i++) {
if (cal(1, i) == cal(n - i + 1, n)) { mx = i; continue; }
int cnt = 0, lp = 1, rp = n - i + 1, x = 0, y = 0;
while (cnt <= 2 && lp <= i) {
int l = 1, r = i - lp + 1, len = 0;
while (l <= r) {
int mid = l + r >> 1; // cout << l << ' ' << r << '\n';
if (cal(lp, lp + mid - 1) ==
cal(rp, rp + mid - 1)) len = mid, l = mid + 1;
else r = mid - 1;
}
if (lp + len <= i) {
if (!x) x = lp + len;
else y = lp + len; cnt++;
}
lp += len + 1, rp += len + 1;
}
if (cnt == 3) continue;
if (cnt == 1) {
if (t[x] == s[n - i + x]) ans[x] = i;
if (t[n - i + x] == s[x]) ans[n - i + x] = i;
} else {
if (y == n - i + x && s[x] == t[y] && s[n - i + y] == t[y]) ans[y] = i;
if (x == n - i + y && s[n - i + x] == t[x] && s[y] == t[y]) ans[x] = i;
}
}
for (int i = 1; i <= n; i++) {
// cout << ans[i] << ' ';
if (s[i] == t[i]) cout << mx << '\n';
else cout << max(min({mx, i - 1, n - i}), ans[i]) << '\n';
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7728kb
input:
cbaababaabacbaababaabacbaabacbaababaabacbaaba dabbababbabaabbafabbgbaabfebaabzababbayaabcac
output:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 17 17 17 17 17 17 17 17 17 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 3 1 1
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%