Task: | Järjestys |
Sender: | xenial |
Submission time: | 2022-01-22 14:02:15 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | details |
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:58: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()), ab(s.sz()), aa(s.sz()), ba(s.sz());int ac = 0, bc = 0;for (int i = 0; i < s.sz(); i++) {ab[i] = ac;bb[i] = bc;if (s[i] == 'B') bc++;else ac++;}if (bc == 0 && ac == 0) {cout << 0 << endl;continue;}ac = 0, bc = 0;for (int i = s.sz() - 1; i >= 0; i--) {if (s[i] == 'A') ac++;else bc++;aa[i] = ac;ba[i] = bc;}int ms = INT_MAX;for (int i = 0; i < s.sz(); i++) {if (bb[i] == aa[i]) ms = min(ms, bb[i]);}cout << ms << endl;}}