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

Code

#include <bits/stdc++.h>

typedef long long ll;

#define M 1000000007

using namespace std;

void test_case() {
	string s;

    cin >> s;

    // ahne?

    int on = (int)s.length();

    while(true) {
        //cout << s << endl;
        int n = (int)s.length();
        map<char, int> most;

        for (int i = 0; i < n; ++i) {
            most[s[i]]++;
        }

        int c = 0;
        char mf = '!';

        for (auto it = most.begin(); it != most.end(); it++) {
            c++;
            if (mf == '!') {
                mf = it->first;
            } else if (most[mf] < it->second) {
                mf = it->first;
            }
        }

        if (c <= 1) break;

        if (s[0] != mf) {
            //cout << "here" << endl;
            string ns = "";
            bool r = false;
            for (int i = 0; i < n; ++i) {
                if (s[i+1] == mf && !r) {
                    i++;
                    r = true;
                    continue;
                }
                ns += s[i];
            }
            s = ns;
        } else {
            string ns;
            bool r = false;
            for (int i = 1; i < n; ++i) {
                if (s[i] != mf && !r) {
                    r = true;
                    continue;
                }
                ns += s[i];
            }
            s = ns;
        }
    }

    cout << on - (int)s.length();
}

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";
        //cout << endl;
	}

	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
...

Test 2

Group: 2

Verdict: ACCEPTED

input
100
CCAAACBCBBCCACBBBCCACCCBABBCAB...

correct output
48
4
4
96
70
...

user output
48
4
4
96
70
...