#include <bits/stdc++.h>
#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)5e5 + 7;
int n;
int q;
int l,r;
int u[N];
string a;
main () {
cin >> n;
cin >> a;
cin >> q;
while (q --) {
int sum = 0,sum1 = 0,f = 0;
cin >> l >> r;
l --,r --;
for (int i = l; i <= r; i ++) {
if (a[i] == 'T' && f == 0) sum ++;
else if (a[i] == 'T' && f > 0) f --;
else f ++;
}
f = 0;
for (int i = r; i >= l; i --) {
if (a[i] == 'T' && f == 0) sum1 ++;
else if (a[i] == 'T' && f > 0) f --;
else f ++;
}
cout << max(sum,sum1) << endl;
}
}
Compilation message
election.cpp:24:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |