Submission #570095

#TimeUsernameProblemLanguageResultExecution timeMemory
570095TsiannisElection (BOI18_election)C++14
0 / 100
3084 ms212 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...