Submission #166786

#TimeUsernameProblemLanguageResultExecution timeMemory
166786muhi1112Doktor (COCI17_doktor)C++17
100 / 100
289 ms45176 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define f1 first #define s2 second #define pb push_back #define mp make_pair #define ll long long #define fri(a) freopen(a,"r",stdin); #define fro(a) freopen(a,"w",stdout); const int N=5e5+5; int n,ans1,ans,maxl,maxr,l,r; int main(){ //fri("in.txt"); //fro("out.txt"); ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; vector<int>v[2*n+5],pre(n+5,0),dizi(n+5); for(int i=1;i<=n;i++){ cin>>dizi[i]; v[dizi[i]+i].pb(abs(dizi[i]-i)); if(dizi[i]==i)pre[i]++; } for(int i=1;i<=n;i++){ pre[i]+=pre[i-1]; //cout<<pre[i]<<endl; } for(int i=0;i<=2*n;i++){ sort(v[i].begin(),v[i].end()); for(int j=0;j<v[i].size();j++){ l=(i-v[i][j])/2; r=(i+v[i][j])/2; ans1=j+pre[l]+pre[n]-pre[r]; //cout<<l<<" "<<r<<" "<<ans1<<endl; if(ans1>ans){ maxl=l; maxr=r; ans=ans1; } } } cout<<dizi[maxl]<<" "<<dizi[maxr]<<endl; return 0; }

Compilation message (stderr)

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