#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5.1e5;
int N, Q;
string S;
string go(string s) {
string t;
int cur = 0;
for (char c : s) {
if (c == 'C') {
cur++;
t += c;
} else if (cur > 0) {
cur--;
t += c;
}
}
return t;
}
int solve(string s) {
string t = go(s);
reverse(t.begin(), t.end());
t = go(t);
return int(s.size() - t.size());
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N >> S >> Q;
while (Q--) {
int l, r; cin >> l >> r; l--;
cout << solve(S.substr(l, r-l)) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
376 KB |
Output is correct |
2 |
Correct |
27 ms |
376 KB |
Output is correct |
3 |
Correct |
33 ms |
344 KB |
Output is correct |
4 |
Correct |
21 ms |
376 KB |
Output is correct |
5 |
Correct |
18 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
376 KB |
Output is correct |
2 |
Correct |
27 ms |
376 KB |
Output is correct |
3 |
Correct |
33 ms |
344 KB |
Output is correct |
4 |
Correct |
21 ms |
376 KB |
Output is correct |
5 |
Correct |
18 ms |
376 KB |
Output is correct |
6 |
Execution timed out |
3049 ms |
1460 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
376 KB |
Output is correct |
2 |
Correct |
27 ms |
376 KB |
Output is correct |
3 |
Correct |
33 ms |
344 KB |
Output is correct |
4 |
Correct |
21 ms |
376 KB |
Output is correct |
5 |
Correct |
18 ms |
376 KB |
Output is correct |
6 |
Execution timed out |
3049 ms |
1460 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |