#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
for(; q; --q) {
int l, r;
cin >> l >> r;
--l, --r;
vector <int> t(n, 1);
int balance = 0;
int ans = 0;
for(int i = l; i <= r; i++) {
balance += s[i] == 'C' ? 1 : -1;
if(!t[i]) balance++;
if(balance < 0) {
balance = 0;
ans += t[i];
t[i] = 0;
}
}
balance = 0;
for(int i = r; i >= l; i--) {
balance += s[i] == 'C' ? 1 : -1;
if(!t[i]) balance++;
if(balance < 0) {
balance = 0;
ans += t[i];
t[i] = 0;
}
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
8 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
8 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
380 KB |
Output is correct |
6 |
Execution timed out |
3022 ms |
2044 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
8 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
380 KB |
Output is correct |
6 |
Execution timed out |
3022 ms |
2044 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |