# 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 |
1 |
Incorrect |
9 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |