Submission #340110

# Submission time Handle Problem Language Result Execution time Memory
340110 2020-12-26T22:45:07 Z Ahmad_Hasan Doktor (COCI17_doktor) C++17
100 / 100
168 ms 12012 KB
#include <bits/stdc++.h>
using namespace std;

bool comp(pair<int,int>a,pair<int,int>b){
    return a.second-a.first+1<b.second-b.first+1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);

    int n;
    cin>>n;
    int v[n];
    int prf[n+5];
    prf[0]=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        prf[i+1]=prf[i]+(i+1==v[i]);
    }

    vector<int> mp(n*2+5);
    vector<pair<int,int> >vps(n);
    for(int i=0;i<n;i++){
        vps[i]={min(i+1,v[i]),max(i+1,v[i])};
    }
    sort(vps.begin(),vps.end(),comp);
    int l=0,r=0;
    int mx=prf[n];
    for(int i=0;i<n;i++){
        mp[vps[i].first+vps[i].second]++;
        if(prf[n]-(prf[vps[i].second]-prf[vps[i].first-1])+mp[vps[i].first+vps[i].second]>mx){
            mx=prf[n]-(prf[vps[i].second]-prf[vps[i].first-1])+mp[vps[i].first+vps[i].second];
            l=vps[i].first-1;  r=vps[i].second-1;
        }
    }
    cout<<v[l]<<' '<<v[r]<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 98 ms 7532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2412 KB Output is correct
2 Correct 30 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 11884 KB Output is correct
2 Correct 168 ms 12012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 7020 KB Output is correct
2 Correct 78 ms 11628 KB Output is correct