답안 #161507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161507 2019-11-02T18:27:34 Z Minnakhmetov Palindromic Partitions (CEOI17_palindromic) C++14
35 / 100
10000 ms 496 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 8 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 13 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 8 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 13 ms 376 KB Output is correct
10 Execution timed out 10064 ms 496 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 416 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 8 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 13 ms 376 KB Output is correct
10 Execution timed out 10064 ms 496 KB Time limit exceeded
11 Halted 0 ms 0 KB -