This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |