# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
152829 | phillip | Doktor (COCI17_doktor) | C++14 | 147 ms | 65576 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 n,a[5009],c[5009][5009];
void o(int x)
{
int l=x-1,r=x+1;
while(l>0&&r<n+1)
{
c[l][r]=c[l+1][r-1];
if(a[l]==r)c[l][r]++;
if(a[r]==l)c[l][r]++;
l--;
r++;
}
l=x;r=x+1;
//cout<<'.';
while(l>0&&r<n+1)
{
c[l][r]=c[l+1][r-1];
if(a[l]==r)c[l][r]++;
if(a[r]==l)c[l][r]++;
l--;
r++;
}
}
int l[5009],r[5009];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
l[i]=l[i-1];
if(a[i]==i)l[i]++;
}
for(int i=n;i>=1;i--)
{
r[i]=r[i+1];
if(a[i]==i)r[i]++;
}
for(int i=1;i<=n;i++)
{
if(i==a[i])c[i][i]=1;
o(i);
}
int sum,mx=0,x,y;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
sum=c[i][j]+l[i-1]+r[j+1];
mx=max(sum,mx);
if(mx==sum)
{
x=i;
y=j;
}
}
}
//cout<<c[1][3]<<"\n";
cout<<a[x]<<" "<<a[y];//<<" "<<mx;
}
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... |