Submission #581822

#TimeUsernameProblemLanguageResultExecution timeMemory
581822YaserFaisalXylophone (JOI18_xylophone)C++14
Compilation error
0 ms0 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std; 

static int A[5000];

void solve(int n)
{
    int l = 2 ;
    int a[5001] ;
    int q[5001][5001] ;
    int one = 1 ;
    while ( true )
    {
        q[l][n] = query(l,n) ;
        if ( q[l][n] != n-1 ) break ;
        l++ ;
        one++ ;
    }
    a[one] = 1 ; 
    for ( int i = one-1 ; i >= 1 ; i-- )
    {
        int x = query(i,i+1) ;
        q[i][i+1] = x ;
        if ( a[i+1]-x <= 1 ) a[i] = a[i+1]+x ;
        else if ( a[i+1]+x >= n ) a[i] = a[i+1]-x ;
        else
        {
            int y = query(i,i+2) ;
            q[i][i+2] = y ;
            if ( a[i+1] > a[i+2] )
            {
                if ( y == q[i+1][i+2] || y == x ) a[i] = a[i+1]-x ;
                else a[i] = a[i+1]+x ;
            }
            else
            {
                if ( y == q[i+1][i+2] || y == x ) a[i] = a[i+1]+x ;
                else a[i] = a[i+1]-x ;
            }
        }
    }
    for ( int i = one+1 ; i <= n ; i++ )
    {
        int x = query(i-1,i) ;
        q[i-1][i] = x ;
        if ( a[i-1]-x <= 1 ) a[i] = a[i-1]+x ;
        else if ( a[i-1]+x >= n ) a[i] = a[i-1]-x ;
        else
        {
            int y = query(i-2,i) ;
            q[i-2][i] = y ;
            if ( a[i-1] > a[i-2] )
            {
                if ( y == q[i-2][i-1] || y == x ) a[i] = a[i-1]-x ;
                else a[i] = a[i-1]+x ;
            }
            else
            {
                if ( y == q[i-2][i-1] || y == x ) a[i] = a[i-1]+x ;
                else a[i] = a[i-1]-x ;
            }
        }
    }
    for ( int i = 1 ; i <= n ; i++ ) ans(i,a[i]) ;
}
//query(s,t) , return abs(A[s]-A[t]) 
// answer(i,a) , A[i] = a 

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:65:38: error: 'ans' was not declared in this scope; did you mean 'abs'?
   65 |     for ( int i = 1 ; i <= n ; i++ ) ans(i,a[i]) ;
      |                                      ^~~
      |                                      abs
xylophone.cpp: At global scope:
xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
    5 | static int A[5000];
      |            ^