QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21519 | #2840. 绿绿与串串 | Skyowo# | WA | 55ms | 9616kb | C++14 | 1.4kb | 2022-03-07 14:28:58 | 2022-05-08 03:35:41 |
Judging History
answer
// Skyqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
const int N = 1e6 + 5;
char s[N];
int n, p[N];
bool st[N];
void inline manacher() {
int r = 0, mid = 0;
for (int i = 1; i <= n; i++) {
p[i] = i <= r ? p[2 * mid - i] : 1;
while (i - p[i] > 0 && i + p[i] <= n && s[i + p[i]] == s[i - p[i]])
++p[i];
if (i + p[i] - 1 > r) r = i + p[i] - 1, mid = i;
}
}
int main() {
int T; read(T);
while (T--) {
scanf("%s", s + 1);
n = strlen(s + 1);
manacher();
if (n == 1) st[1] = 1;
for (int i = 1; i <= n; i++) {
if (i + p[i] - 1 == n) st[i] = 1;
}
for (int i = n; i >= 2; i--) {
if (2 * i - 1 <= n) {
if (p[i] == i) st[i] |= st[2 * i - 1];
}
}
for (int i = 1; i <= n; i++)
if (st[i]) printf("%d ", i);
puts("");
for (int i = 1; i <= n; i++) st[i] = 0;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5768kb
input:
7 abcdcb qwqwq qaqaqqq carnation c ab aa
output:
4 6 2 3 4 5 6 7 9 1 2 2
result:
ok 7 lines
Test #2:
score: -100
Wrong Answer
time: 55ms
memory: 9616kb
input:
5 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
15626 31251 62501 125001 250001 500001 250000 499999 1000000 999998 1000000
result:
wrong answer 1st lines differ - expected: '2 3 4 5 6 7 8 9 10 11 12 13 14...96 999997 999998 999999 1000000', found: '15626 31251 62501 125001 250001 500001 '