Submission #1131133

#TimeUsernameProblemLanguageResultExecution timeMemory
1131133pb2008Election (BOI18_election)C++20
28 / 100
10 ms580 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n, q; string s; bool mark[N]; vector <int> ans; void readInput(); void solve(); void writeOutput(); int main() { ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0); readInput(); solve(); writeOutput(); return 0; } void readInput() { cin >> n >> s >> q; } void solve() { for (int i = 0; i < q; i++) { int l, r; cin >> l >> r; int res = 0, cnt = 0; fill(mark, mark + n, false); for (int j = --l; j < r; j++) { cnt += (1 - 2 * (s[j] == 'T')); if (cnt < 0) cnt++, res++, mark[j] = true; } cnt = 0; for (int j = --r; j >= l; j--) { if (mark[j]) continue; cnt += (1 - 2 * (s[j] == 'T')); if (cnt < 0) cnt++, res++; } ans.push_back(res); } } void writeOutput() { for (int x: ans) cout << x << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...