#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
ll const inf = 1e9;
ll const mod = 1e9 + 7;
ld const eps = 1e-9;
int main()
{
int n, q;
string s;
cin >> n;
cin >> s;
cin >> q;
int nulify[n];
memset(nulify, -1, sizeof(nulify));
fr(t, 0, q){
int l, r;
cin >> l >> r;
l --, r --;
int c = 0;
int cnt = 0;
fr(i, l, r + 1){
if(s[i] == 'C') c ++;
else c --;
if(c < 0){
cnt ++;
nulify[i] = t;
c ++;
}
}
c = 0;
for(int i = r; i >= l; i --){
if(s[i] == 'C') c ++;
else if(nulify[i] != t) c --;
if(c < 0){
cnt ++;
c ++;
}
}
cout << cnt << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
376 KB |
Output is correct |
2 |
Correct |
19 ms |
376 KB |
Output is correct |
3 |
Correct |
18 ms |
376 KB |
Output is correct |
4 |
Correct |
19 ms |
376 KB |
Output is correct |
5 |
Correct |
13 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
376 KB |
Output is correct |
2 |
Correct |
19 ms |
376 KB |
Output is correct |
3 |
Correct |
18 ms |
376 KB |
Output is correct |
4 |
Correct |
19 ms |
376 KB |
Output is correct |
5 |
Correct |
13 ms |
380 KB |
Output is correct |
6 |
Execution timed out |
3045 ms |
1488 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
376 KB |
Output is correct |
2 |
Correct |
19 ms |
376 KB |
Output is correct |
3 |
Correct |
18 ms |
376 KB |
Output is correct |
4 |
Correct |
19 ms |
376 KB |
Output is correct |
5 |
Correct |
13 ms |
380 KB |
Output is correct |
6 |
Execution timed out |
3045 ms |
1488 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |