# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480835 | Karabasan | Election (BOI18_election) | C++17 | 3057 ms | 940 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>
#define ll long long
#define fast1 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
int n,t,m;
int pre[500005];
void solve()
{
string AAA;
string s="G";
cin>>n;
cin>>AAA;
s+=AAA;
int q;
scanf("%d",&q);
while(q--)
{
string u=s;
int a,b;
cin>>a>>b;
int c=0;
int t=0;
int mx=0;
for(int i=a;i<=b;i++)
{
if(u[i]=='T')
c++;
else c--;
if(c>0)
{
u[i]='U';
c=0;
mx++;
}
}
int mx2=0;
for(int i=b;i>=a;i--)
{
if(u[i]=='T')
t++;
else if(u[i]=='C')
t--;
mx2=max(mx2,t);
}
mx+=mx2;
cout<<mx<<endl;
}
}
int main()
{
// scanf("%d",&t);
t=1;
while(t--)
{
solve();
}
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... |