#include <bits/stdc++.h>
using namespace std;
#define ll long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n,q;
string s;
cin >> n >> s >> q;
for(int i = 0;i < q;i++){
int l,r;
cin >> l >> r;
vector <bool> vis(n,false);
int c = 0;
int t = 0;
for(int j = l-1; j < r;j++){
if(s.at(j) == 'C'){
c++;
}else{
t++;
if(t > c){
t--;
vis[j] = true;
}
}
}
c = 0;
t = 0;
for(int j = r-1; j >= l-1;j--){
if(s.at(j) == 'C'){
c++;
}else if(!vis[j]){
t++;
if(t > c){
t--;
vis[j] = true;
}
}
}
int res = 0;
for(int j = l-1;j < r;j++){
if(vis[j]){
res++;
}
}
cout << res << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
544 KB |
Output is correct |
4 |
Correct |
5 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
544 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 |
3055 ms |
1276 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
544 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 |
3055 ms |
1276 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |