제출 #852987

#제출 시각아이디문제언어결과실행 시간메모리
852987farukElection (BOI18_election)C++17
28 / 100
3044 ms920 KiB
#include <bits/stdc++.h> #define mp make_pair #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef pair<int, int> pii; int get(string s) { int n = s.size(); vector<bool> nulli(n); int bal = 0; for (int i = 0; i < n; i++) { if (nulli[i]) continue; if (bal == 0 and s[i] == 'T') nulli[i] = true; else if (s[i] == 'T') bal--; else bal++; } bal = 0; for (int i = n - 1; i >= 0; i--) { if (nulli[i]) continue; if (bal == 0 and s[i] == 'T') nulli[i] = true; else if (s[i] == 'T') bal--; else bal++; } return count(all(nulli), true); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >>s; int q; cin >> q; while (q--) { int l, r; cin >> l >> r; r--, l--; cout << get(s.substr(l, r - l + 1)) << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...