제출 #1311586

#제출 시각아이디문제언어결과실행 시간메모리
1311586dm2010Election (BOI18_election)C++20
28 / 100
3094 ms732 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; string S; cin >> S; int Q; cin >> Q; while (Q--) { int L, R; cin >> L >> R; L--; R--; vector<bool> removed(R - L + 1, false); int bal = 0; for (int i = 0; i <= R - L; i++) { if (removed[i]) continue; if (S[L + i] == 'C') bal++; else bal--; if (bal < 0) { removed[i] = true; bal++; } } bal = 0; for (int i = R - L; i >= 0; i--) { if (removed[i]) continue; if (S[L + i] == 'C') bal++; else bal--; if (bal < 0) { removed[i] = true; bal++; } } int ans = 0; for (bool x : removed) ans += x; cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...