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>
# define fi first
# define se second
using namespace std;
int main() {
int N;
string S;
cin>>N;
cin>>S;
int Q;
cin>>Q;
for(int tc = 1;tc<=Q;tc++) {
int a, b;
cin>>a>>b;
if(a > b) swap(a, b);
a--;
b--;
int c = 0, d = 0, e = 0;
for(int i=a;i<=b;i++) {
if(S[i] == 'T') {
if(c == 0) d++;
else c--;
} else c++;
}
c = 0;
for(int i=b;i>=a;i--) {
if(S[i] == 'T') {
if(c == 0) e++;
else c--;
} else c++;
}
printf("%d\n", max(d, e));
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |