Submission #434113

#TimeUsernameProblemLanguageResultExecution timeMemory
434113AmineTrabelsiElection (BOI18_election)C++14
28 / 100
3067 ms1008 KiB
#include "bits/stdc++.h" using namespace std; // Hi int main(){ ios::sync_with_stdio(0);cin.tie(0); int n; cin>>n; string s; cin>>s; int q; cin>>q; while(q--){ int l,r; cin>>l>>r; l--,r--; vector<bool> vis(n+1,0); int cnt = 0; int ans = 0; for(int i=l;i<=r;i++){ cnt += (s[i] == 'C' ? 1 : -1); //cout << i<<" "<<cnt<< '\n'; if(cnt < 0){ vis[i] = 1; cnt++; ans++; } } cnt = 0; for(int i=r;i>=l;i--){ if(vis[i])continue; cnt += (s[i] == 'C' ? 1 : -1); //cout << i<<" "<<cnt<< '\n'; if(cnt < 0){ cnt++; ans++; } } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...