Submission #343394

#TimeUsernameProblemLanguageResultExecution timeMemory
343394ijxjdjdElection (BOI18_election)C++14
28 / 100
3071 ms1076 KiB
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> s(N); for (int i = 0; i < N; i++) { char c; cin >> c; if (c == 'C') { s[i] = 1; } else { s[i] = -1; } } int Q; cin >> Q; while (Q-->0) { int l, r; cin >> l >> r; l--, r--; unordered_set<int> touched; int cur = 0; for (int i = l; i <= r; i++) { cur += s[i]; if (cur < 0) { cur = 0; touched.insert(i); } } cur = 0; for (int i = r; i >= l; i--) { if (!touched.count(i)) { cur += s[i]; if (cur < 0) { cur = 0; touched.insert(i); } } } cout << touched.size() << '\n'; } // for (auto i : touched) { // cerr << i << " "; // } // int ans = (int)(1e9); // for (int j = 0; j < (1<<N); j++) { // int cur = 0; // bool flag = false; // for (int i = 0; i < N; i++) { // if (!(j&(1<<i))) cur += s[i]; // if (cur < 0) flag = true; // } // cur = 0; // for (int i = N-1; i >= 0; i--) { // if (!(j&(1<<i))) cur += s[i]; // if (cur < 0) flag = true; // } // if (!flag) { // ans = min(ans, __builtin_popcount(j)); // } // } // if (ans != touched.size()) { // for (int e : s) { // cout << e << " "; // } // cout << '\n'; // cout << ans << '\n'; // for (int i : touched) { // cout << i << " "; // } // break; // } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...