# include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 2;
int n, q, u[N];
string s;
int main(){
cin >> n >> s >> q;
s = ' ' + s;
while(q --){
int l, r, ans = 0, a = 0, b = 0;
cin >> l >> r;
for(int i = l; i <= r; i ++){
if(s[i] == 'C')
a ++;
else
b ++;
if(b > a){
b --;
u[i] = 1;
ans ++;
}
}
a = b = 0;
for(int i = r; i >= l; i --){
if(s[i] == 'C')
a ++;
else
if(!u[i])
b ++;
if(b > a){
b --;
ans ++;
}
u[i] = 0;
}
cout << ans << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
376 KB |
Output is correct |
2 |
Correct |
22 ms |
464 KB |
Output is correct |
3 |
Correct |
19 ms |
540 KB |
Output is correct |
4 |
Correct |
15 ms |
540 KB |
Output is correct |
5 |
Correct |
11 ms |
584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
376 KB |
Output is correct |
2 |
Correct |
22 ms |
464 KB |
Output is correct |
3 |
Correct |
19 ms |
540 KB |
Output is correct |
4 |
Correct |
15 ms |
540 KB |
Output is correct |
5 |
Correct |
11 ms |
584 KB |
Output is correct |
6 |
Runtime error |
6 ms |
1088 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
376 KB |
Output is correct |
2 |
Correct |
22 ms |
464 KB |
Output is correct |
3 |
Correct |
19 ms |
540 KB |
Output is correct |
4 |
Correct |
15 ms |
540 KB |
Output is correct |
5 |
Correct |
11 ms |
584 KB |
Output is correct |
6 |
Runtime error |
6 ms |
1088 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |