Submission #1018404

#TimeUsernameProblemLanguageResultExecution timeMemory
1018404YassirSalamaElection (BOI18_election)C++17
0 / 100
721 ms344 KiB
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; #define endl "\n" #define int ll using ull=unsigned long long; using ll=long long; using pii=pair<int,int>; const int mod=1e9+7; #define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n"; template <typename T> istream& operator>>(istream& is, vector<T> &a) { copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;} #ifdef IOI template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__); #else #define dbg(...) 1337; #endif #define pb push_back #define F first #define S second #define all(v) v.begin(),v.end() const int mxn=2e5+100; signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int n; cin>>n; string s; cin>>s; int q; cin>>q; vector<int> v(n); for(int i=0;i<n;i++) v[i]=(s[i]=='C'?1:-1); auto check = [&](int l,int r,vector<int> &a){ int p=0; for(int i=l;i<=r;i++){ p+=a[i]; if(p<0) return false; } return p>=0; }; for(int i=0;i<q;i++){ int l,r; cin>>l>>r; l--,r--; int ans=1e18; for(int j=0;j<=r-l+1;j++){ int x=j; vector<int> vv=v; for(int i=l;i<=r&&x-1>=0;i++){ if(vv[i]==-1) vv[i]=0,x--; } if(x) break; if(check(l,r,vv)==false) continue; int s=0; int calc=0; for(int i=r;i>=l;i--){ s+=vv[i]; if(s<0){ s-=vv[i]; calc++; } } // dbg(j,calc,vv) ans=min(ans,j+calc); } cout<<ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...