Submission #340110

#TimeUsernameProblemLanguageResultExecution timeMemory
340110Ahmad_HasanDoktor (COCI17_doktor)C++17
100 / 100
168 ms12012 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...