제출 #230564

#제출 시각아이디문제언어결과실행 시간메모리
230564Dilshod_ImomovXylophone (JOI18_xylophone)C++17
0 / 100
6 ms384 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; void solve(int n) { int l = 0, 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 ); a[ind] = 1; set < int > st; answer( ind, 1 ); for ( int i = 2; i <= n; i++ ) { st.insert(i); } if ( ind + 1 <= n ) { int x = query( ind, ind + 1 ); a[ind + 1] = x + 1; answer( ind + 1, x + 1 ); } if ( ind - 1 > 0 ) { int x = query( ind - 1, ind ); a[ind - 1] = x + 1; answer( ind - 1, x + 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 ) { a[i] = x + d; answer( i, x + d ); continue; } if ( x + d > n ) { a[i] = x - d; answer( i, x - d ); 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 ); } else { a[i] = x + d; answer( i, x + d ); } } 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 ) { a[i] = x + d; answer( i, x + d ); continue; } if ( x + d > n ) { a[i] = x - d; answer( i, x - d ); 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 ); } else { a[i] = x + d; answer( i, x + d ); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...