Submission #1215332

#TimeUsernameProblemLanguageResultExecution timeMemory
1215332lopkusElection (BOI18_election)C++20
28 / 100
3093 ms952 KiB
#include <bits/stdc++.h> signed main() { int n; std::cin >> n; std::string c; std::cin >> c; std::vector<char> a(n + 1); for(int i = 1; i <= n; i++) { a[i] = c[i - 1]; } int q; std::cin >> q; while(q--) { int l, r; std::cin >> l >> r; int pref = 0; std::vector<int> was(n + 1); int ans = 0; for(int i = l; i <= r; i++) { pref += (a[i] == 'C' ? 1 : - 1); if(pref < 0) { was[i] = 1; ans += 1; pref += 1; } } pref = 0; for(int i = r; i >= l; i--) { if(was[i]) { continue; } pref += (a[i] == 'C' ? 1 : - 1); if(pref < 0) { was[i] = 1; ans += 1; pref += 1; } } std::cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...