Submission #581856

# Submission time Handle Problem Language Result Execution time Memory
581856 2022-06-23T07:24:26 Z YaserFaisal Xylophone (JOI18_xylophone) C++14
47 / 100
125 ms 98580 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std; 

static int A[5000];

void solve(int n)
{
    int ans[5001] , pre_query[5001][5001] , found[100001] ;
    int one = 1 ;
    // searching for the one 
    int l = 1 , r = n-1 ;
    while(l<=r)
    {
        int m = (l+r)/2 ;
        pre_query[m][n] = query(m,n) ;
        if ( pre_query[m][n] == n-1  ) l = m+1 ;
        else r = m-1 ;
    }
    one = r ; 
    ans[one] = 1 ; 
    found[1] = 1 ;
    //==================================
    for ( int i = one+1 ; i <= n ; i++ )
    {
        int x , y ;
        x = pre_query[i-1][i] = query(i-1,i) ;
        if ( ans[i-1]+x > n || found[ans[i-1]+x] == 1 ) ans[i] = ans[i-1]-x ;
        else if ( ans[i-1]-x <= 1 || found[ans[i-1]-x] == 1 ) ans[i] = ans[i-1]+x ;
        else
        {
            y = pre_query[i-2][i] = query(i-2,i) ;
            if ( ans[i-1] > ans[i-2] )
            {
                if ( y == pre_query[i-2][i-1] || y == x ) ans[i] = ans[i-1]-x ;
                else ans[i] = ans[i-1]+x ;
            }
            else
            {
                if ( y == pre_query[i-2][i-1] || y == x ) ans[i] = ans[i-1]+x ;
                else ans[i] = ans[i-1]-x ;
            }
        }
    }
    //========================
    for ( int i = one-1 ; i >= 1 ; i-- )
    {
        int x , y ;
        x = pre_query[i][i+1] = query(i,i+1) ;
        if ( ans[i+1]+x > n || found[ans[i+1]+x] == 1 ) ans[i] = ans[i+1]-x ;
        else if ( ans[i+1]-x <= 1 || found[ans[i+1]-x] == 1 ) ans[i] = ans[i+1]+x ;
        else
        {
            y = pre_query[i][i+2] = query(i,i+2) ;
            if ( ans[i+1] > ans[i+2] )
            {
                if ( y == pre_query[i+1][i+2] || y == x ) ans[i] = ans[i+1]-x ;
                else ans[i] = ans[i+1]+x ;
            }
            else
            {
                if ( y == pre_query[i+1][i+2] || y == x ) ans[i] = ans[i+1]+x ;
                else ans[i] = ans[i+1]-x ;
            }
        }
    }
    //========================
    for ( int i = 1 ; i <= n ; i++ ) answer(i,ans[i]) ;
}
//query(s,t) , return abs(A[s]-A[t]) 
// answer(i,a) , A[i] = a 

Compilation message

xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
    5 | static int A[5000];
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 38 ms 98504 KB Output is correct
2 Correct 39 ms 98464 KB Output is correct
3 Correct 40 ms 98460 KB Output is correct
4 Correct 36 ms 98560 KB Output is correct
5 Correct 37 ms 98484 KB Output is correct
6 Correct 41 ms 98520 KB Output is correct
7 Correct 41 ms 98576 KB Output is correct
8 Correct 40 ms 98544 KB Output is correct
9 Correct 38 ms 98464 KB Output is correct
10 Correct 39 ms 98512 KB Output is correct
11 Correct 40 ms 98480 KB Output is correct
12 Correct 41 ms 98504 KB Output is correct
13 Correct 47 ms 98452 KB Output is correct
14 Correct 42 ms 98496 KB Output is correct
15 Correct 39 ms 98532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 98504 KB Output is correct
2 Correct 39 ms 98464 KB Output is correct
3 Correct 40 ms 98460 KB Output is correct
4 Correct 36 ms 98560 KB Output is correct
5 Correct 37 ms 98484 KB Output is correct
6 Correct 41 ms 98520 KB Output is correct
7 Correct 41 ms 98576 KB Output is correct
8 Correct 40 ms 98544 KB Output is correct
9 Correct 38 ms 98464 KB Output is correct
10 Correct 39 ms 98512 KB Output is correct
11 Correct 40 ms 98480 KB Output is correct
12 Correct 41 ms 98504 KB Output is correct
13 Correct 47 ms 98452 KB Output is correct
14 Correct 42 ms 98496 KB Output is correct
15 Correct 39 ms 98532 KB Output is correct
16 Correct 48 ms 98444 KB Output is correct
17 Correct 47 ms 98560 KB Output is correct
18 Correct 51 ms 98488 KB Output is correct
19 Correct 56 ms 98576 KB Output is correct
20 Correct 54 ms 98576 KB Output is correct
21 Correct 57 ms 98576 KB Output is correct
22 Correct 50 ms 98512 KB Output is correct
23 Correct 59 ms 98540 KB Output is correct
24 Correct 58 ms 98576 KB Output is correct
25 Correct 49 ms 98504 KB Output is correct
26 Correct 53 ms 98460 KB Output is correct
27 Correct 56 ms 98576 KB Output is correct
28 Correct 52 ms 98576 KB Output is correct
29 Correct 53 ms 98572 KB Output is correct
30 Correct 45 ms 98580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 98504 KB Output is correct
2 Correct 39 ms 98464 KB Output is correct
3 Correct 40 ms 98460 KB Output is correct
4 Correct 36 ms 98560 KB Output is correct
5 Correct 37 ms 98484 KB Output is correct
6 Correct 41 ms 98520 KB Output is correct
7 Correct 41 ms 98576 KB Output is correct
8 Correct 40 ms 98544 KB Output is correct
9 Correct 38 ms 98464 KB Output is correct
10 Correct 39 ms 98512 KB Output is correct
11 Correct 40 ms 98480 KB Output is correct
12 Correct 41 ms 98504 KB Output is correct
13 Correct 47 ms 98452 KB Output is correct
14 Correct 42 ms 98496 KB Output is correct
15 Correct 39 ms 98532 KB Output is correct
16 Correct 48 ms 98444 KB Output is correct
17 Correct 47 ms 98560 KB Output is correct
18 Correct 51 ms 98488 KB Output is correct
19 Correct 56 ms 98576 KB Output is correct
20 Correct 54 ms 98576 KB Output is correct
21 Correct 57 ms 98576 KB Output is correct
22 Correct 50 ms 98512 KB Output is correct
23 Correct 59 ms 98540 KB Output is correct
24 Correct 58 ms 98576 KB Output is correct
25 Correct 49 ms 98504 KB Output is correct
26 Correct 53 ms 98460 KB Output is correct
27 Correct 56 ms 98576 KB Output is correct
28 Correct 52 ms 98576 KB Output is correct
29 Correct 53 ms 98572 KB Output is correct
30 Correct 45 ms 98580 KB Output is correct
31 Correct 67 ms 98504 KB Output is correct
32 Correct 78 ms 98568 KB Output is correct
33 Correct 112 ms 98556 KB Output is correct
34 Correct 76 ms 98572 KB Output is correct
35 Correct 86 ms 98576 KB Output is correct
36 Incorrect 125 ms 98472 KB Wrong Answer [2]
37 Halted 0 ms 0 KB -