Submission #582950

# Submission time Handle Problem Language Result Execution time Memory
582950 2022-06-24T15:50:38 Z 600Mihnea Palindromic Partitions (CEOI17_palindromic) C++17
35 / 100
10000 ms 340 KB
#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];

bool is_palind(int l, int r) {
  if (l > r) {
    return 1;
  }
  return a[l] == a[r] && is_palind(l + 1, r - 1);
}

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;
    }
    dp[0] = 0;
    for (int l = 1; l <= n; l++) {
      for (int r = l; r <= n; r++) {
        bool is = is_palind(l, r);
        if (is && (r - l + 1) % 2 == 0) {
          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";
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 18 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 18 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Execution timed out 10090 ms 340 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 18 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Execution timed out 10090 ms 340 KB Time limit exceeded
11 Halted 0 ms 0 KB -