#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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |