#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> c(n, 0);
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
l--;
fill(c.begin() + l, c.begin() + r, 0);
int b = 0;
for (int i = l; i < r; i++) {
if (s[i] == 'C') {
b++;
} else {
b--;
if (b < 0) {
b = 0;
c[i] = 1;
}
}
}
b = 0;
for (int i = r - 1; i >= l; i--) {
if (s[i] == 'C') {
b++;
} else if (!c[i]) {
b--;
if (b < 0) {
b = 0;
c[i] = 1;
}
}
}
int ans = count(c.begin() + l, c.begin() + r, 1);
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
340 KB |
Output is correct |
2 |
Correct |
11 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
340 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
340 KB |
Output is correct |
2 |
Correct |
11 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
340 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3068 ms |
1444 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
340 KB |
Output is correct |
2 |
Correct |
11 ms |
340 KB |
Output is correct |
3 |
Correct |
11 ms |
340 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
3068 ms |
1444 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |