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

Code

#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <algorithm>
#include <vector>
#include <fstream>
#include <set>
#include <unordered_map>
#include <queue>
#include <climits>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define LOOP(i,a,l) for (int i = a; i < l; i++)
#define LUO_VERKKO LOOP(i,0,m) {int a,b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a);}
#define COLLECT for (int i = 0; i < n; i++) cin >> s[i]
#define PRINT_LIST(l) for (int i = 0; i < l.size(); i++) cout << l[i] << " "
#define S second
#define F first
#define A 999999999999999999LL
#define M 1000000007
//https://cses.fi/dt/
int n;
int k;
#define N (1<<17)
int main() {
	cin >> n;
	vector<int> bs;
	for (int i = 0; i < n; i++)
	{
		string m; cin >> m;
		int co = 0;
		int len = m.length();
		bs.clear();
		int a = 0;
		for (int j = 0; j < len; j++) {
			if (m[j] == 'A') a++;
		}
		for (int j = 0; j < len; j++)
		{
			char c = m[j];
			if (c == 'B') {
				bs.push_back(j);
			}
			else {
				if (bs.empty() || j < a) continue;
				bs.erase(bs.begin());
				co++;
			}
		}
		cout << co << "\n";
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
1000
BBAABBBBAAABABBBAABBAABAAAABBB...

correct output
10
10
20
3
20
...

user output
10
10
20
3
20
...
Truncated