# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154524 | phillip | Doktor (COCI17_doktor) | C++14 | 495 ms | 45972 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 N 500009
using namespace std;
int n;
int prs[N],a[N];
vector<int>rs[2*N];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{
prs[i]+=prs[i-1];
if(i==a[i])prs[i]++;
}
for(int i=1;i<=n;i++)
{
rs[i+a[i]].push_back(abs(a[i]-i));
}
for(int i=2;i<=2*n;i++)sort(rs[i].begin(),rs[i].end());
int mx=-N,ml=1,mr=1;
for(int i=2;i<=2*n;i++)
{
int o=0;
for(int j=0;j<rs[i].size();j++)
{
o++;
int c=i,rad=rs[i][j],ans;
int l=(c-rad)/2,r=(c+rad)/2;
ans=o-prs[r]+prs[l-1];
if(ans>=mx)
{
mx=ans;
ml=l;
mr=r;
}
}
}
cout<<a[ml]<<" "<<a[mr];
}
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... |