CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:ABC-poisto
Sender:ollpu
Submission time:2020-10-16 18:45:08 +0300
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED42
#2ACCEPTED58
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Code

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  for (int Ti = 0; Ti < T; ++Ti) {
    string w;
    cin >> w;
    int n = w.size();
    int dp[n][n] {};
    for (int s = 2; s <= n; s += 2) {
      for (int i = 0; i+s <= n; ++i) {
        int j = i+s-1;
        if (w[i] != w[j]) dp[i][j] = s == 2 || dp[i+1][j-1];
        for (int k = 2; k <= s-2; k += 2) {
          dp[i][j] |= dp[i][i+k-1] && dp[i+k][j];
        }
      }
    }
    int dp2[n];
    for (int i = 0; i < n; ++i) {
      dp2[i] = 0;
      if (i) dp2[i] = dp2[i-1];
      for (int s = 2; s <= i+1; s += 2) {
        if (dp[i-s+1][i]) {
          if (s == i+1) dp2[i] = s;
          else dp2[i] = max(dp2[i], s+dp2[i-s]);
        }
      }
    }
    cout << dp2[n-1] << endl;
  }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
100
CABC
BABCCBCA
CBBCBBAC
ACAA
...

correct output
4
8
8
2
2
...

user output
4
8
8
2
2
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
100
CCAAACBCBBCCACBBBCCACCCBABBCAB...

correct output
48
4
4
96
70
...

user output
48
4
4
96
70
...
Truncated