CSES - Datatähti 2022 loppu - Results
Submission details
Task:Järjestys
Sender:Anniiiz
Submission time:2022-01-22 13:15:16 +0200
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails

Code

#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
using ll = long long;


int main() {
  ll t;
  cin >> t;
  for (int j = 0; j < t; ++j) {
    string s;
    cin >> s;
    ll a = 0;
    ll b = s.size()-1;
    ll c = 0;
    ll d = 0;
    ll siirrot = 0;
    if (s[a] == 'B') c++;
    if (s[b] == 'A') d++;
    if (c && d) siirrot++;
    while (a != b) {
      //cout << a << " " << b << " " << c << " " << d << endl;
      if (c <= d) {
        a++;
        if (a == b) break;
        if (s[a] == 'B') {
          c++;
          if (c == d) siirrot++;
        }
      }
      else {
        b--;
        if (b == a) break;
        if (s[b] == 'A') {
          d++;
          if (c == d) siirrot++;
        }
      }
    }
    cout << siirrot << endl;
  }
}

Test details

Test 1

Verdict: ACCEPTED

input
1000
BBAABBBBAAABABBBAABBAABAAAABBB...

correct output
10
10
20
3
20
...

user output
10
10
20
3
20
...
Truncated