Submission #227667

#TimeUsernameProblemLanguageResultExecution timeMemory
227667muhammad_hokimiyonXylophone (JOI18_xylophone)C++14
47 / 100
2256 ms736 KiB
#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 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] );
        }
        set < int > s;
        for( int j = 1; j <= n; j++ ){
            s.insert(b[j]);
            f &= (b[j] <= n && b[j] >= 1);
        }
        f &= ((int)s.size() == n);
        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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...