Submission #152829

#TimeUsernameProblemLanguageResultExecution timeMemory
152829phillipDoktor (COCI17_doktor)C++14
60 / 100
147 ms65576 KiB
#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)

doktor.cpp: In function 'int main()':
doktor.cpp:65:25: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout<<a[x]<<" "<<a[y];//<<" "<<mx;
                         ^
doktor.cpp:65:17: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout<<a[x]<<" "<<a[y];//<<" "<<mx;
                 ^~~
#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...