#include <bits/stdc++.h>
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <int> a(n + 1);
for ( int i = 1; i <= n; i++ ){
char x; cin >> x;
a[i] = (x == 'C' ? 1 : -1);
}
int q; cin >> q;
while ( q-- ){
int l, r; cin >> l >> r;
vector <int> er(n + 1);
int cnt = 0;
for ( int i = r; i >= l; i-- ){
if ( er[i] ) continue;
cnt += a[i];
if ( cnt < 0 ){
er[i] = 1, cnt = 0;
}
}
cnt = 0;
for ( int i = l; i <= r; i++ ){
if ( er[i] ) continue;
if ( a[i] == -1 ){
if ( cnt == 0 ) er[i] = 1;
else cnt -= 1;
} else{
cnt += 1;
}
}
cout << accumulate(er.begin(), er.end(), 0) << '\n';
}
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
500 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
500 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Execution timed out |
3044 ms |
1492 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
500 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Execution timed out |
3044 ms |
1492 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |