This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
const int NN = 5e3 + 7;
int b[NN];
void solve(int n)
{
int i = 1 , j = n;
for( ; i < j; i++,j-- ){
if( query( i + 1 , j - 1 ) != n - 1 ){
while( query( i + 1 , j ) == n - 1 )i += 1;
while( query( i , j - 1 ) == n - 1 )j -= 1;
break;
}
}
b[i] = 1;
b[j] = n;
if( i != 1 )b[i - 1] = query( i - 1 , i ) + 1;
if( i + 1 < j )b[i + 1] = query( i , i + 1 ) + 1;
if( j - 1 > i + 1 )b[j - 1] = n - query( j - 1 , j );
if( j != n )b[j + 1] = n - query( j , j + 1 );
for( int h = i - 2; h >= 1; h-- ){
int x = query( h , h + 1 );
int y = query( h , h + 2 );
int x1 = b[h + 1];
int y1 = b[h + 2];
if( x1 > y1 ){
if( y == x1 - y1 )b[h] = x1 - x;
else if( x == y )b[h] = x1 - x;
else b[h] = x1 + x;
}else{
if( y == x + y1 - x1 )b[h] = x1 - x;
else if( y == y1 - x1 )b[h] = x1 + x;
else b[h] = x1 + x;
}
}
for( int h = i + 2; h <= j - 2; h++ ){
int x = query( h - 1 , h );
int y = query( h - 2 , h );
int x1 = b[h - 1];
int y1 = b[h - 2];
if( x1 > y1 ){
if( y == x1 - y1 )b[h] = x1 - x;
else if( x == y )b[h] = x1 - x;
else b[h] = x1 + x;
}else{
if( y == x + y1 - x1 )b[h] = x1 - x;
else if( y == y1 - x1 )b[h] = x1 + x;
else b[h] = x1 + x;
}
}
for( int h = j + 2; h <= n; h++ ){
int x = query( h - 1 , h );
int y = query( h - 2 , h );
int x1 = b[h - 1];
int y1 = b[h - 2];
if( x1 > y1 ){
if( y == x1 - y1 )b[h] = x1 - x;
else if( x == y )b[h] = x1 - x;
else b[h] = x1 + x;
}else{
if( y == x + y1 - x1 )b[h] = x1 - x;
else if( y == y1 - x1 )b[h] = x1 + x;
else b[h] = x1 + x;
}
}
for( int h = 1; h <= n; h++ ){
answer( h , b[h] );
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |