Submission #116924

#TimeUsernameProblemLanguageResultExecution timeMemory
116924DajuncticDoktor (COCI17_doktor)C++17
100 / 100
377 ms42744 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5e5+5; int n, a[N]; typedef pair<int,int> ii; #define fi first #define se second int pre[N]; vector<ii> Split[N<<1]; int main(){ cin >> n; for(int i=1;i<=n;i++){ cin >> a[i]; ii Sw = {i,a[i]}; if(i>a[i]) swap(Sw.fi,Sw.se); Split[i+a[i]].push_back(Sw); pre[i] = pre[i-1] + (i==a[i]); } int ans = pre[n]; ii bes = {1,1}; for(int x=2;x<=(n<<1);x++){ if(!Split[x].empty()){ sort(Split[x].begin(),Split[x].end()); reverse(Split[x].begin(),Split[x].end()); } for(int i=0;i<Split[x].size();i++){ ii katarina = Split[x][i]; int num = i + 1 + pre[n] - (pre[katarina.se] - pre[katarina.fi-1]); if (num > ans) { ans = num; bes = katarina; } } } cout << a[bes.fi] << " " << a[bes.se]; return 0; }

Compilation message (stderr)

doktor.cpp: In function 'int main()':
doktor.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<Split[x].size();i++){
               ~^~~~~~~~~~~~~~~~
#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...