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

Compiler report

input/code.cpp: In function 'int slow(const string&)':
input/code.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size() - 1; ++i) {
                  ~~^~~~~~~~~~~~~~

Code

#include <iostream>
#include <map>
#include <string>

using namespace std;

map<string, int> cache;

int slow(const string &s) {
	if (s.size() == 0) return 0;
	if (cache.find(s) != cache.end()) return cache[s];
	int maxways = 0;
	for (int i = 0; i < s.size() - 1; ++i) {
		if (s[i] != s[i+1]) {
			string s2 = s;
			s2.erase(i, 2);
			maxways = max(maxways, slow(s2) + 2);
		}
	}
	cache[s] = maxways;
	return maxways;
}

int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		string s;
		cin >> s;
		cout << slow(s) << 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:

input
100
CCAAACBCBBCCACBBBCCACCCBABBCAB...

correct output
48
4
4
96
70
...

user output
(empty)