This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
const int N = 1e6 + 5;
int dp[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = s.size();
fill(dp, dp + n, -1);
dp[0] = 0;
for (int i = 0; i < n / 2; i++) {
if (dp[i] == -1)
continue;
for (int j = 1; j * 2 <= n - i * 2; j++) {
if (s.substr(i, j) == s.substr(n - i - j, j)) {
dp[i + j] = max(dp[i + j], dp[i] + 1);
}
}
}
int ans = 0;
for (int i = 0; i <= n / 2; i++) {
ans = max(ans, dp[i] * 2 + (i * 2 < n));
}
cout << ans << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |