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 "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
const int NN = 5e3 + 7;
int d[NN];
int d1[NN];
int b[NN];
int c[NN];
int get( int x , int y , int x1 , int y1 )
{
if( x1 > y1 ){
if( y == x1 - y1 )return x1 - x;
if( x == y )return x1 - x;
return x1 + x;
}else{
if( y == x + y1 - x1 )return x1 - x;
if( y == y1 - x1 )return x1 + x;
return x1 + x;
}
}
void solve(int n)
{
for( int i = 1; i <= n - 1; i++ ){
d[i] = query( i , i + 1 );
}
for( int i = 1; i <= n - 2; i++ ){
d1[i] = query( i , i + 2 );
}
for( int i = 1; i < n; i++ ){
bool f = true;
b[i] = 1;
if( i != 1 )b[i - 1] = d[i - 1] + 1;
b[i + 1] = d[i] + 1;
for( int j = i - 2; j >= 1; j-- ){
b[j] = get( d[j] , d1[j] , b[j + 1] , b[j + 2] );
}
for( int j = i + 2; j <= n; j++ ){
b[j] = get( d[j - 1] , d1[j - 2] , b[j - 1] , b[j - 2] );
}
for( int j = 1; j <= n; j++ ){
f &= (b[j] <= n && b[j] >= 1);
if( !f )break;
f &= (c[b[j]] == 0);
c[b[j]] = 1;
}
for( int j = 1; j <= n; j++ ){
c[j] = 0;
}
for( int j = 1; j <= n - 1; j++ ){
f &= (d[j] == abs(b[j + 1] - b[j]));
}
for( int j = 1; j <= n - 2; j++ ){
f &= (d1[j] == abs(max({b[j] , b[j + 1] , b[j + 2]}) - min({b[j] , b[j + 1] , b[j + 2]})));
}
if( !f )continue;
for( int h = 1; h <= n; h++ ){
answer( h , b[h] );
}
return;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |