#include <bits/stdc++.h>
#define ll long long
#define st first
#define nd second
#define pii pair <ll, ll>
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, n, m) for (ll i = (n); i >= (m); i --)
using namespace std;
const long long N = 1e6 + 5;
ll n, a[N], q;
bool del[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
rep(i, 1, n) {
char ch;
cin >> ch;
if (ch == 'T') a[i] = -1; else a[i] = 1;
}
cin >> q;
while (q --) {
int l, r;
cin >> l >> r;
int b = 0, ans = 0;
rep(i, l, r) {
b += a[i];
if (b < 0) b ++, ans ++, del[i] = true;
}
b = 0;
rrep(i, r, l) {
if (!del[i]) {
b += a[i];
if (b < 0) b ++, ans ++;
}
del[i] = false;
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
2910 ms |
2124 KB |
Output is correct |
7 |
Execution timed out |
3073 ms |
1632 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
2910 ms |
2124 KB |
Output is correct |
7 |
Execution timed out |
3073 ms |
1632 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |