Task: | Järjestys |
Sender: | xenial |
Submission time: | 2022-01-22 13:45:19 +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: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; } }