CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:ABC-poisto
Sender:Mahtimursu
Submission time:2020-10-16 21:58:17 +0300
Language:C++ (C++11)
Status:READY
Result:42
Feedback
groupverdictscore
#1ACCEPTED42
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2--2details

Code

#include <bits/stdc++.h>

typedef long long ll;

#define M 1000000007

using namespace std;

unordered_map<string, int> m;

int rec(string s) {
    int n = (int)s.length();
    int best = n;

    if (m[s]) return m[s];

    for (int i = 1; i < n; ++i) {
        if (s[i-1] != s[i]) {
            string ns;

            for (int j = 0; j < n; ++j) {
                if (j == i - 1) {
                    j++;
                    continue;
                }
                ns += s[j];
            }
            best = min(best, rec(ns));
        }
    }

    m[s] = best;
    return best;
}

void test_case() {
	string s;
    cin >> s;

    int n = (int)s.length();
    //cout << "here" << endl;
    cout << n - rec(s);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		test_case();
		cout << "\n";
	}

	return 0;
}

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:

input
100
CCAAACBCBBCCACBBBCCACCCBABBCAB...

correct output
48
4
4
96
70
...

user output
(empty)