# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
852923 | Benmath | Election (BOI18_election) | C++14 | 3033 ms | 1980 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.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, q;
cin >> n;
string s;
cin >> s;
cin >> q;
vector<int>ans;
while (q--){
int a, b;
cin >> a >> b;
a--;
b--;
vector<int>v;
for(int i = a; i <= b; i++){
if(s[i] == 'C'){
v.push_back(1);
}else{
v.push_back(-1);
}
}
int sum = 0;
for(int i = 0; i < v.size(); i++){
sum = sum + v[i];
if(sum < 0){
v[i] = 0;
sum = 0;
}
}
sum = 0;
for(int i = v.size()-1; i >= 0; i--){
sum = sum + v[i];
if(sum < 0){
v[i] = 0;
sum = 0;
}
}
int brojac = 0;
for(int i = 0; i < v.size(); i++){
if(v[i] == 0){
brojac++;
}
}
ans.push_back(brojac);
}
for (int i = 0; i < ans.size(); i++){
cout << ans[i] << endl;
}
}
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... |