Submission #850241

#TimeUsernameProblemLanguageResultExecution timeMemory
850241RifalElection (BOI18_election)C++14
0 / 100
1 ms344 KiB
#include <bits/stdc++.h> #include <fstream> #define endl '\n' #define mod 998244353 #define INF 9000000000 #define cin fin #define cout fout //#define fi first //#define se second using namespace std; ofstream fout("elections.out"); ifstream fin("elections.in"); int main() { ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); int n; cin >> n; string s; cin >> s; int q; cin >> q; while(q--) { int l, r; cin >> l >> r; bool ok[n] = {}; int cur = 0; int ans = 0; for(int i = l-1; i < r; i++) { if(s[i] == 'C') { cur++; } else if(cur-1 >= 0) { cur--; } else { ok[i] = 1; ans++; } } cur = 0; for(int i = r-1; i >= l-1; i--) { if(s[i] == 'C') { cur++; } else if(cur-1 >= 0 && ok[i] == 0) { cur--; } else if(ok[i] == 0) { ans++; } } cout << ans << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...