#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int N = (int) 1e6 + 7;
const int INF = (int) 1e9 + 7;
int n;
int a[N];
int dp[N];
int big[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/// freopen ("input.txt", "r", stdin);
int Tests;
cin >> Tests;
for (int tc = 1; tc <= Tests; tc++) {
{
string str;
cin >> str;
n = (int) str.size();
int Low = 0, High = n - 1;
for (int Step = 1; Step <= n; Step++) {
if (Step % 2 == 0) {
a[Step] = str[Low++] - 'a';
} else {
a[Step] = str[High--] - 'a';
}
}
}
for (int i = 0; i <= n + 1; i++) {
dp[i] = -INF;
big[i] = 0;
}
dp[0] = 0;
for (int i = 1; i < n; i++) {
int r = i + 1;
while (1 <= 2 * i + 1 - r && r <= n && a[2 * i + 1 - r] == a[r]) {
big[r] = max(big[r], i);
r++;
}
}
for (int r = 1; r <= n; r++) {
if (int i = big[r]) {
int l = 2 * i + 1 - r;
dp[r] = max(dp[r], dp[l - 1] + 1);
}
}
int sol = 2 * dp[n];
for (int i = 0; i < n; i++) {
sol = max(sol, 2 * dp[i] + 1);
}
cout << sol << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
239 ms |
588 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
239 ms |
588 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Execution timed out |
10063 ms |
12188 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |