CSES - Datatähti 2022 loppu - Results
Submission details
Task:Järjestys
Sender:xenial
Submission time:2022-01-22 13:45:19 +0200
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.01 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < s.sz(); i++) {
                         ~~^~~~~~~~
input/code.cpp:59:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < s.sz(); i++) {
                         ~~^~~~~~~~
input/code.cpp: In function 'void set_io(std::__cxx11::string)':
input/code.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen((filename + ".in").c_str(), "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen((filename + ".out").c_str(), "w", stdout);...

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define sz size
#define rsz resize
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>

void set_io(string filename = "") {
    ios::sync_with_stdio(0);
    cin.tie(0);

    if (filename != "") {
        freopen((filename + ".in").c_str(), "r", stdin);
        freopen((filename + ".out").c_str(), "w", stdout);
    }
}

int T;

int main() {
	set_io("");

    cin >> T;

    while (T--) {
        string s; cin >> s;

        vector<int> bb(s.sz()), aa(s.sz());

        int bc = 0;
        for (int i = 0; i < s.sz(); i++) {
            bb[i] = bc;
            if (s[i] == 'B') bc++;
        }

        if (bc == 0) {
            cout << 0 << endl;
            continue;
        }

        int ac = 0;
        for (int i = s.sz() - 1; i >= 0; i--) {
            aa[i] = ac;
            if (s[i] == 'A') ac++;
        }

        if (ac == 0) {
            cout << 0 << endl;
            continue;
        }

        int ms = INT_MAX;
        for (int i = 0; i < s.sz(); i++) {
            if (s[i] != 'A') continue;

            if (bb[i] == 1 && aa[i] == 0) ms = min(ms, 1);
            else if (bb[i] == aa[i] + 1) ms = min(ms, bb[i]);
            else if (bb[i] == aa[i]) ms = min(ms, bb[i]);
        }
        cout << ms << endl;
    }
}

Test details

Test 1

Verdict:

input
1000
BBAABBBBAAABABBBAABBAABAAAABBB...

correct output
10
10
20
3
20
...

user output
10
10
20
3
20
...