#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,q;
cin>>n;
string s;
cin>>s;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;l--;r--;
int ans=0;
vector <int> nu(s.size(),-1);
int cnt2=0,cnt1=0;
for(int i=l;i<=r;i++){
if(s[i]=='C')cnt1++;
else cnt2++;
if(cnt2>cnt1){
nu[i]=0;
ans++;
cnt2--;
}
}
cnt2=0;cnt1=0;
for(int i=r;i>=l;i--){
if(s[i]=='C')cnt1++;
else if(s[i]=='T' && nu[i]==-1)cnt2++;
if(cnt2>cnt1){
nu[i]=0;
ans++;
cnt2--;
}
}
cout<<ans<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
4 |
Correct |
6 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
4 |
Correct |
6 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
3033 ms |
1576 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 |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
4 |
Correct |
6 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
3033 ms |
1576 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |