n = int(input())
s = input()
q = int(input())
for _ in range(q):
a,b = map(int,input().split())
curr_c=0
curr_t=0
a-=1
curr = [1]*n
for i in range(a,b):
if s[i]=="C":
curr_c+=1
continue
curr_t+=1
if curr_t>curr_c:
curr_t-=1
curr[i]=0
b-=1
curr_c=0
curr_t=0
for i in range(b,a-1,-1):
if s[i]=="C":
curr_c+=1
continue
if curr[i]==0:
continue
curr_t+=1
if curr_t>curr_c:
curr_t-=1
curr[i]=0
print(curr.count(0))
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
366 ms |
24596 KB |
Output is correct |
2 |
Correct |
334 ms |
24924 KB |
Output is correct |
3 |
Correct |
371 ms |
24004 KB |
Output is correct |
4 |
Correct |
316 ms |
24816 KB |
Output is correct |
5 |
Correct |
364 ms |
24360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
366 ms |
24596 KB |
Output is correct |
2 |
Correct |
334 ms |
24924 KB |
Output is correct |
3 |
Correct |
371 ms |
24004 KB |
Output is correct |
4 |
Correct |
316 ms |
24816 KB |
Output is correct |
5 |
Correct |
364 ms |
24360 KB |
Output is correct |
6 |
Execution timed out |
3069 ms |
28256 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
366 ms |
24596 KB |
Output is correct |
2 |
Correct |
334 ms |
24924 KB |
Output is correct |
3 |
Correct |
371 ms |
24004 KB |
Output is correct |
4 |
Correct |
316 ms |
24816 KB |
Output is correct |
5 |
Correct |
364 ms |
24360 KB |
Output is correct |
6 |
Execution timed out |
3069 ms |
28256 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |