# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
643292 | Kripton | Election (BOI18_election) | C++14 | 3060 ms | 2400 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 mindr[500001];
int sumst[500001],sumdr[500002];
char s[500001];
int logue[500001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,i,j,q,a,b,minst;
cin>>n>>ws>>(s+1)>>ws;
for(i=1;i<=n;i++)
sumst[i]=sumst[i-1]+(s[i]=='C')-(s[i]=='T');
for(i=n;i>=1;i--)
sumdr[i]=sumdr[i+1]+(s[i]=='C')-(s[i]=='T');
cin>>q;
while(q--)
{
cin>>a>>b;
int ans=0;
mindr[b+1]=1e9;
for(i=b;i>=a;i--)
mindr[i]=min(mindr[i+1],sumdr[i]);
int minst=1e9;
for(i=a;i<=b;i++)
{
minst=min(minst,sumst[i]);
ans=max(ans,max(-(minst-sumst[a-1]),0)+max(-(mindr[i+1]-sumdr[b+1]),0));
}
cout<<ans<<'\n';
}
return 0;
}
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... |