# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
581819 | 2022-06-23T06:58:39 Z | YaserFaisal | Xylophone (JOI18_xylophone) | C++14 | 0 ms | 0 KB |
#include "xylophone.h" #include <bits/stdc++.h> static int A[5000]; void solve(int n) { int l = 2 ; int a[5001] ; int q[5001][5001] ; int one = 1 ; while ( true ) { q[l][n] = query(l,n) ; if ( q[l][n] != n-1 ) break ; l++ ; one++ ; } a[one] = 1 ; for ( int i = one-1 ; i >= 1 ; i-- ) { int x = query(i,i+1) ; q[i][i+1] = x ; if ( a[i+1]-x <= 1 ) a[i] = a[i+1]+x ; else if ( a[i+1]+x >= n ) a[i] = a[i+1]-x ; else { int y = (i,i+2) ; q[i][i+2] = y ; if ( a[i+1] > a[i+2] ) { if ( y == q[i+1][i+2] || y == x ) a[i] = a[i+1]-x ; else a[i] = a[i+1]+x ; } else { if ( y == q[i+1][i+2] || y == x ) a[i] = a[i+1]+x ; else a[i] = a[i+1]-x ; } } } for ( int i = one+1 ; i <= n ; i++ ) { int x = query(i-1,i) ; q[i-1][i] = x ; if ( a[i-1]-x <= 1 ) a[i] = a[i-1]+x ; else if ( a[i-1]+x >= n ) a[i] = a[i-1]-x ; else { int y = (i-2,i) ; q[i-2][i] = y ; if ( a[i-1] > a[i-2] ) { if ( y == q[i-2][i-1] || y == x ) a[i] = a[i-1]-x ; else a[i] = a[i-1]+x ; } else { if ( y == q[i-2][i-1] || y == x ) a[i] = a[i-1]+x ; else a[i] = a[i-1]-x ; } } } for ( int i = 1 ; i <= n ; i++ ) ans(i,a[i]) ; } //query(s,t) , return abs(A[s]-A[t]) // answer(i,a) , A[i] = a