# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
73533 | 2018-08-28T11:43:21 Z | Pajaraja | Xylophone (JOI18_xylophone) | C++17 | 0 ms | 0 KB |
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int a[5007],s[5007],sgn[5007],inv[5007]; void solve(int n) { int znk=1; sgn[0]=1; for(int i=0;i<n-1;i++) s[i]=answer(i,i+1); for(int i=2;i<n;i++) { if(s[i-2]+s[i-1]==answer(i-2,i)) sgn[i-1]=sgn[i-2]; else sgn[i-1]=-sgn[i-2]; } int m=0,cur=0; for(int i=1;i<n;i++) { cur+=sgn[i-1]*s[i-1]; m=min(m,cur); } cur=-m; a[0]=-m; for(int i=0;i<n;i++) { cur+=sgn[i-1]*s[i-1]; a[i]=cur; } for(int i=0;i<n;i++) inv[a[i]]=i; if(inv[0]>inv[n-1]) for(int i=0;i<n;i++) a[i]=n-1-a[i]; for(int i=0;i<n;i++) answer(i,a[i]); }