# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
235173 | topovik | Doktor (COCI17_doktor) | C++14 | 481 ms | 89440 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 f first
#define s second
#define pb push_back
#define INF 1000000000
#define N (long)1e5+2
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
int n;
cin>>n;
int b[n];
for (int i=0; i<n; i++) cin>>b[i];
int a[n];
for (int i=0; i<n; i++) a[i]=b[i]-i-1;
vector <int> lf[n*2],rg[n*2];
for (int i=0; i<n; i++)
if (a[i]<0) rg[i*2+a[i]].pb(a[i]);
else
if (a[i]>0) lf[i*2+a[i]].pb(a[i]);
int pr[n];
pr[-1]=0;
for (int i=0; i<n; i++) pr[i]=pr[i-1]+(a[i]==0);
int ans=0,l=0,r=0;
for (int i=0; i<n*2; i++)
{
lf[i].pb(0);
sort(lf[i].begin(),lf[i].end());
int kol=1*(i%2==0 && a[i/2]==0);
int j1=0;
for (int i1=0; i1<lf[i].size() && (i+lf[i][i1])<n*2; i1++)
{
while (j1<rg[i].size() && abs(rg[i][j1])<=lf[i][i1]) j1++;
int mx=lf[i][i1];
int c1=i1+j1-(pr[(i+mx)/2]-pr[(i-mx)/2-1])+kol;
if (c1>ans) ans=c1,l=b[(i-mx)/2],r=b[(i+mx)/2];
}
j1=0;
for (int i1=0; i1<rg[i].size() && (i+rg[i][i1])>=0; i1++)
{
while (j1<lf[i].size() && lf[i][j1]<=abs(rg[i][i1])) j1++;
int mx=abs(rg[i][i1]);
int c1=i1+j1-(pr[(i+mx)/2]-pr[(i-mx)/2-1])+kol;
if (c1>ans) ans=c1,l=b[(i-mx)/2],r=b[(i+mx)/2];
}
}
if (l==0) cout<<1<<" "<<1;
else cout<<l<<" "<<r;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |