Submission #996157

#TimeUsernameProblemLanguageResultExecution timeMemory
996157cnn008Xylophone (JOI18_xylophone)C++17
100 / 100
407 ms97492 KiB
#include <bits/stdc++.h> #include "xylophone.h" using namespace std; int a[5005],d[5005][5005]; void solve(int n){ int _=query(1,2); for(int i=3; i<=n; i++) d[i-2][i]=query(i-2,i); for(int i=2; i<=n; i++) d[i-1][i]=query(i-1,i); for(int i=1; i<=n; i++){ a[1]=i; for(int __=-1; __<=1; __+=2){ vector <int> vis(n+1,0); vis[a[1]]++; a[2]=a[1]+__*_; if(a[2]>=1 and a[2]<=n) vis[a[2]]++; int cnt=0; for(int j=3; j<=n; j++){ int v=d[j-2][j]; int l=d[j-1][j]; if(v==max(a[j-1],a[j-2])-min(a[j-1],a[j-2])){ if(a[j-1]>a[j-2]) a[j]=a[j-1]-l; else a[j]=a[j-1]+l; }else{ int ifmin=a[j-1]-l; int ifmax=a[j-1]+l; if(ifmin>0 and max({a[j-2],a[j-1]})-ifmin==v) a[j]=ifmin; else a[j]=ifmax; } if(a[j]>=1 and a[j]<=n) vis[a[j]]++; } int fir=1,last=0; for(int j=1; j<=n; j++) if(a[j]==1) fir=j; for(int j=1; j<=n; j++) if(a[j]==n) last=j; if(fir>last) continue; bool ck=1; for(int i=1; i<=n; i++) if(vis[i]!=1) ck=0; if(!ck) continue; for(int i=1; i<=n; i++) answer(i,a[i]); return; } } }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:18:8: warning: unused variable 'cnt' [-Wunused-variable]
   18 |    int cnt=0;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...