#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
int y[200001];
signed main(){
boost;
int n; cin >> n;
string a; cin >> a;
int q; cin >> q;
while(q--){
int l,r, cur = 0, ans = 0; cin >> l >> r;
l--; r--;
for(int i = l; i <= r; i++){
y[i] = 0;
if(a[i] == 'T') cur--;
else cur++;
if(cur < 0){
y[i]++;
cur++;
ans++;
}
}
cur = 0;
for(int i = r; i >= l; i--){
if(y[i]) continue;
if(a[i] == 'T') cur--;
else cur++;
if(cur < 0){
ans++;
cur++;
}
}
cout << ans << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
352 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
352 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
264 KB |
Output is correct |
6 |
Execution timed out |
3061 ms |
1336 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
352 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
264 KB |
Output is correct |
6 |
Execution timed out |
3061 ms |
1336 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |