Submission #1311582

#TimeUsernameProblemLanguageResultExecution timeMemory
1311582dm2010Election (BOI18_election)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; string s; cin >> s; while (Q--) { int L, R; cin >> L >> R; L--; R--; int balance = 0; int removeForward = 0; for (int i = L; i <= R; i++) { if (s[i] == 'C') balance++; else balance--; if (balance < 0) { removeForward++; balance++; } } balance = 0; int removeBackward = 0; for (int i = R; i >= L; i--) { if (s[i] == 'C') balance++; else balance--; if (balance < 0) { removeBackward++; balance++; } } cout << max(removeForward, removeBackward) << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...