This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 10000009
string s;
ll solve1(ll l,ll r,ll cc,ll ct)
{
if (ct>cc)
return INF;
if (l>r)
return 0;
if (s[l]=='C')
return solve1(l+1,r,cc+1,ct);
return min(solve1(l+1,r,cc,ct)+1,solve1(l+1,r,cc,ct+1));
}
ll solve2(ll l,ll r,ll cc,ll ct)
{
if (ct>cc)
return INF;
if (l>r)
return 0;
if (s[r]=='C')
return solve2(l,r-1,cc+1,ct);
return min(solve2(l,r-1,cc,ct)+1,solve2(l,r-1,cc,ct+1));
}
int main ()
{
ll n; cin>>n;
cin>>s;
ll q; cin>>q;
while(q--)
{
ll l,r;
cin>>l>>r; l--;r--;
ll ans1=solve1(l,r,0,0);
ll ans2=solve2(l,r,0,0);
cout<<max(ans1,ans2)<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |