# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1082400 | SulA | Election (BOI18_election) | C++17 | 4 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int solve(string s) {
int pref = 0, min_pref = 0;
for (char c : s) {
pref += (c == 'C' ? 1 : -1);
min_pref = min(pref, min_pref);
}
int suff = 0, min_suff = 0;
reverse(s.begin(), s.end());
for (char c : s) {
suff += (c == 'C' ? 1 : -1);
min_suff = min(suff, min_suff);
}
return max(-min_pref, -min_suff);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin >> n;
string s; cin >> s;
int q; cin >> q; while (q--) {
int l,r; cin >> l >> r;
l--, r--;
cout << solve(s.substr(l, r-l+1)) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |