Submission #230588

#TimeUsernameProblemLanguageResultExecution timeMemory
230588Dilshod_ImomovXylophone (JOI18_xylophone)C++17
100 / 100
89 ms416 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; void solve(int n) { int l = 1, r = n, ind = 0, md; while ( l <= r ) { md = (l + r) / 2; if ( query( md, n ) == n - 1 ) { l = md + 1; ind = md; } else { r = md - 1; } } vector < int > a( n + 1 ), used(n + 1); a[ind] = 1; answer( ind, 1 ); used[1] = 1; if ( ind + 1 <= n ) { int x = query( ind, ind + 1 ); a[ind + 1] = x + 1; answer( ind + 1, x + 1 ); used[x + 1] = 1; } if ( ind - 1 > 0 ) { int x = query( ind - 1, ind ); a[ind - 1] = x + 1; answer( ind - 1, x + 1 ); used[x + 1] = 1; } for ( int i = ind + 2; i <= n; i++ ) { int x = a[ i - 1 ], y = a[i - 2]; int d = query( i - 1, i ); if ( x - d < 1 || used[x - d] ) { a[i] = x + d; answer( i, x + d ); used[x + d] = 1; continue; } if ( x + d > n || used[x + d] ) { a[i] = x - d; answer( i, x - d ); used[x - d] = 1; continue; } int q = query( i - 2, i ); int mx = max( { x, y, x - d } ), mn = min( { x, y, x - d } ); if ( q == mx - mn ) { a[i] = x - d; answer( i, x - d ); used[x - d] = 1; } else { a[i] = x + d; answer( i, x + d ); used[x + d] = 1; } } for ( int i = ind - 2; i > 0; i-- ) { int x = a[ i + 1 ], y = a[i + 2]; int d = query( i, i + 1 ); if ( x - d < 1 || used[x - d] ) { a[i] = x + d; answer( i, x + d ); used[x + d] = 1; continue; } if ( x + d > n ) { a[i] = x - d; answer( i, x - d ); used[x - d] = 1; continue; } int q = query( i, i + 2 ); int mx = max( { x, y, x - d } ), mn = min( { x, y, x - d } ); if ( q == mx - mn ) { a[i] = x - d; answer( i, x - d ); used[x - d] = 1; } else { a[i] = x + d; answer( i, x + d ); used[x + d] = 1; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...