# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
565627 | 1zaid1 | Election (BOI18_election) | C++14 | 3072 ms | 540 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int M = 2e6 + 5, MOD = 1e9+7;
int res(string s) {
int ans = 0;
int a = 0, b = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'T') a++;
if (s[i] == 'C') b++;
if (a > b) {
a--;
s[i] = 0;
ans++;
}
}
a = 0;
b = 0;
for (int i = s.size()-1; i >= 0; i--) {
if (s[i] == 'T') a++;
if (s[i] == 'C') b++;
if (a > b) {
a--;
s[i] = 0;
ans++;
}
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
srand(time(0));
int n;
cin >> n;
string s;
cin >> s;
int t;
cin >> t;
while (t--) {
int l, r;
cin >> l >> r;
cout << res(s.substr(l-1, r-l+1)) << endl;
}
return 0;
}
/*
11
CCCTTTTTTCC
3
1 11
4 9
1 6
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |