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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:24:9: warning: array subscript has type 'char' [-Wchar-subscripts]
    cnt[u]++;
         ^

Code

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000007
using namespace std;
int cnt[333];
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio();
int t;
cin >> t;
for(int g=0; g<t; g++) {
string s;
cin >> s;
for(int i='A'; i<='C'; i++) {
cnt[i] = 0;
}
list<char> ls;
for(auto u:s) {
cnt[u]++;
ls.push_back(u);
}
vector<pair<int,int>> v;
for(int i='A'; i<='C'; i++) {
v.push_back(make_pair(cnt[i], i));
}
bool ok = true;
int ans = 0;
while(ok && !ls.empty()) {
ok = false;
sort(v.rbegin(), v.rend());
auto it = ls.begin();
while(next(it, 1) != ls.end()) {
if((*it == v[0].second && *next(it, 1) == v[1].second) || (*it == v[1].second && *next(it, 1) == v[0].second)) {
ls.erase(it, next(it, 2));
ans += 2;
v[0].first--;
v[1].first--;
ok = true;
break;
}
it++;
}
if(ok)
continue;
it = ls.begin();
while(next(it, 1) != ls.end()) {
if((*it == v[0].second && *next(it, 1) == v[2].second) || (*it == v[2].second && *next(it, 1) == v[0].second)) {
ls.erase(it, next(it, 2));
ans += 2;
v[0].first--;
v[2].first--;
ok = true;
break;
}
it++;
}
}
cout << ans << "\n";
}
}

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