#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 998244353
#define INF 9000000000
#define cin fin
#define cout fout
//#define fi first
//#define se second
using namespace std;
ofstream fout("elections.out");
ifstream fin("elections.in");
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int n; cin >> n;
string s; cin >> s;
int q; cin >> q;
while(q--) {
int l, r; cin >> l >> r;
bool ok[n] = {};
int cur = 0;
int ans = 0;
for(int i = l-1; i < r; i++) {
if(s[i] == 'C') {
cur++;
}
else if(cur-1 >= 0) {
cur--;
}
else {
ok[i] = 1;
ans++;
}
}
cur = 0;
for(int i = r-1; i >= l-1; i--) {
if(s[i] == 'C') {
cur++;
}
else if(cur-1 >= 0 && ok[i] == 0) {
cur--;
}
else if(ok[i] == 0) {
ans++;
}
}
cout << ans << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |