제출 #1311583

#제출 시각아이디문제언어결과실행 시간메모리
1311583dm2010Election (BOI18_election)C++20
0 / 100
3 ms332 KiB
#include <bits/stdc++.h> using namespace std; int solve_forward(const string &s) { int balance = 0; int removed = 0; for (char c : s) { if (c == 'C') balance++; else balance--; if (balance < 0) { removed++; balance++; } } return removed; } int solve_backward(const string &s) { int balance = 0; int removed = 0; for (int i = (int)s.size() - 1; i >= 0; i--) { if (s[i] == 'C') balance++; else balance--; if (balance < 0) { removed++; balance++; } } return removed; } 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--; string sub = S.substr(L, R - L + 1); int fwd = solve_forward(sub); int bwd = solve_backward(sub); cout << max(fwd, bwd) << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...