# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
637461 | Benmath | Election (BOI18_election) | C++14 | 11 ms | 312 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;
int main(){
int n;
cin>>n;
string s;
cin>>s;
int q;
cin>>q;
while(q--){
int l,r;
cin>>l>>r;
l--;
r--;
vector<int>v1;
vector<int>v2;
int ro=0;
for(int i=l;i<=r;i++){
if(s[i]=='C'){
if(i!=l and s[i-1]=='T'){
v1.push_back(abs(ro));
ro=0;
}
ro++;
}else{
ro--;
}
}
if(s[r]=='T'){
v1.push_back(abs(ro));
}
ro=0;
for(int i=r;i>=l;i--){
if(s[i]=='C'){
if(i!=r and s[i+1]=='T'){
v2.push_back(abs(ro));
ro=0;
}
ro++;
}else{
ro--;
}
}
if(s[l]=='T'){
v2.push_back(abs(ro));
}
reverse(v2.begin(),v2.end());
int ans=0;
for(int i=0;i<v1.size();i++){
ans=ans+max(v1[i],v2[i]);
}
cout<<ans<<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... |