CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:ABC-poisto
Sender:Mahtimursu
Submission time:2020-10-16 19:08:04 +0300
Language:C++11
Status:READY
Result:42
Feedback
groupverdictscore
#1ACCEPTED42
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#20.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();
        char c = 'A';
        int mxlen = -1;
        int start = 0;
        for (int i = 1; i < n; ++i) {
            if (s[start] != s[i]) {
                if (mxlen < i - start) {
                    c = s[start];
                }
                mxlen = max(mxlen, i - start);
                start = i;
            }
        }
        if (n - start > mxlen && mxlen != -1) {
            c = s[n-1];
        }

        if (mxlen == -1) break;

        //cout << mxlen << " " << c << " " << start << "\n";

        // remove from start if possible

        if (s[0] != c) {
            //cout << "here" << endl;
            string ns = "";
            bool r = false;
            for (int i = 0; i < n; ++i) {
                if (s[i+1] == c && !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] != c && !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:

input
100
CCAAACBCBBCCACBBBCCACCCBABBCAB...

correct output
48
4
4
96
70
...

user output
44
4
4
96
70
...