#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
for(int i = 0; i<q; i++){
bool use[n];
for(int j = 0; j<n; j++){
use[j] = true;
}
int cur = 0;
int l, r;
cin >> l >> r;
l--;
r--;
int ans = 0;
for(int j = l; j<=r; j++){
if(s[j]=='T' && cur==0){
ans++;
use[j] = false;
}
else if(s[j]=='T'){
cur--;
}
else{
cur++;
}
}
cur = 0;
for(int j = r; j>=l; j--){
if(s[j]=='T' && cur==0 && use[j]){
use[j] = false;
ans++;
}
else if(s[j]=='T' && use[j]){
cur--;
}
else if(s[j]=='C'){
cur++;
}
}
cout << ans << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
248 KB |
Output is correct |
2 |
Correct |
15 ms |
484 KB |
Output is correct |
3 |
Correct |
15 ms |
484 KB |
Output is correct |
4 |
Correct |
14 ms |
544 KB |
Output is correct |
5 |
Correct |
15 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
248 KB |
Output is correct |
2 |
Correct |
15 ms |
484 KB |
Output is correct |
3 |
Correct |
15 ms |
484 KB |
Output is correct |
4 |
Correct |
14 ms |
544 KB |
Output is correct |
5 |
Correct |
15 ms |
544 KB |
Output is correct |
6 |
Execution timed out |
3011 ms |
1220 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
248 KB |
Output is correct |
2 |
Correct |
15 ms |
484 KB |
Output is correct |
3 |
Correct |
15 ms |
484 KB |
Output is correct |
4 |
Correct |
14 ms |
544 KB |
Output is correct |
5 |
Correct |
15 ms |
544 KB |
Output is correct |
6 |
Execution timed out |
3011 ms |
1220 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |