#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define ll long long
#define db double
#define pb push_back
#define pf push_front
#define newl "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second
#define MOD 1000000007
using namespace std;
int main()
{
fast
//setIO("");
//freopen("filename.in", "r", stdin);
//freopen("filename.out", "w", stdout);
ll n; cin >> n;
string s; cin >> s;
ll q; cin >> q;
while (q--)
{
ll l, r; cin >> l >> r;
l--, r--;
ll c = 0, t = 0, cnt1 = 0;
for (ll i = l; i <= r; i++)
{
if (s[i] == 'C') c++;
else t++;
if (t > c)
{
t--;
cnt1++;
}
}
c = 0, t = 0;
ll cnt2 = 0;
for (ll i = r; i >= l; i--)
{
if (s[i] == 'C') c++;
else t++;
if (t > c)
{
t--;
cnt2++;
}
}
cout << max(cnt1, cnt2) << newl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |