Submission #581819

# Submission time Handle Problem Language Result Execution time Memory
581819 2022-06-23T06:58:39 Z YaserFaisal Xylophone (JOI18_xylophone) C++14
Compilation error
0 ms 0 KB
#include "xylophone.h"
#include <bits/stdc++.h>

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 = (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 = (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

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:28:22: warning: left operand of comma operator has no effect [-Wunused-value]
   28 |             int y = (i,i+2) ;
      |                      ^
xylophone.cpp:50:23: warning: left operand of comma operator has no effect [-Wunused-value]
   50 |             int y = (i-2,i) ;
      |                      ~^~
xylophone.cpp:64:38: error: 'ans' was not declared in this scope; did you mean 'abs'?
   64 |     for ( int i = 1 ; i <= n ; i++ ) ans(i,a[i]) ;
      |                                      ^~~
      |                                      abs
xylophone.cpp: At global scope:
xylophone.cpp:4:12: warning: 'A' defined but not used [-Wunused-variable]
    4 | static int A[5000];
      |            ^