답안 #581860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581860 2022-06-23T07:28:37 Z YaserFaisal Xylophone (JOI18_xylophone) C++14
100 / 100
112 ms 98700 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 ;
            }
        }
        found[ans[i]] = 1 ;
    }
    //========================
    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 ;
            }
        }
        found[ans[i]] = 1 ;
    }
    //========================
    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];
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 98484 KB Output is correct
2 Correct 41 ms 98512 KB Output is correct
3 Correct 40 ms 98572 KB Output is correct
4 Correct 39 ms 98492 KB Output is correct
5 Correct 44 ms 98504 KB Output is correct
6 Correct 49 ms 98544 KB Output is correct
7 Correct 47 ms 98564 KB Output is correct
8 Correct 38 ms 98468 KB Output is correct
9 Correct 38 ms 98524 KB Output is correct
10 Correct 37 ms 98464 KB Output is correct
11 Correct 38 ms 98476 KB Output is correct
12 Correct 39 ms 98468 KB Output is correct
13 Correct 42 ms 98448 KB Output is correct
14 Correct 42 ms 98504 KB Output is correct
15 Correct 47 ms 98536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 98484 KB Output is correct
2 Correct 41 ms 98512 KB Output is correct
3 Correct 40 ms 98572 KB Output is correct
4 Correct 39 ms 98492 KB Output is correct
5 Correct 44 ms 98504 KB Output is correct
6 Correct 49 ms 98544 KB Output is correct
7 Correct 47 ms 98564 KB Output is correct
8 Correct 38 ms 98468 KB Output is correct
9 Correct 38 ms 98524 KB Output is correct
10 Correct 37 ms 98464 KB Output is correct
11 Correct 38 ms 98476 KB Output is correct
12 Correct 39 ms 98468 KB Output is correct
13 Correct 42 ms 98448 KB Output is correct
14 Correct 42 ms 98504 KB Output is correct
15 Correct 47 ms 98536 KB Output is correct
16 Correct 42 ms 98572 KB Output is correct
17 Correct 44 ms 98468 KB Output is correct
18 Correct 48 ms 98452 KB Output is correct
19 Correct 52 ms 98576 KB Output is correct
20 Correct 53 ms 98492 KB Output is correct
21 Correct 61 ms 98460 KB Output is correct
22 Correct 58 ms 98564 KB Output is correct
23 Correct 46 ms 98580 KB Output is correct
24 Correct 45 ms 98580 KB Output is correct
25 Correct 50 ms 98528 KB Output is correct
26 Correct 54 ms 98568 KB Output is correct
27 Correct 53 ms 98504 KB Output is correct
28 Correct 54 ms 98572 KB Output is correct
29 Correct 52 ms 98464 KB Output is correct
30 Correct 56 ms 98600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 98484 KB Output is correct
2 Correct 41 ms 98512 KB Output is correct
3 Correct 40 ms 98572 KB Output is correct
4 Correct 39 ms 98492 KB Output is correct
5 Correct 44 ms 98504 KB Output is correct
6 Correct 49 ms 98544 KB Output is correct
7 Correct 47 ms 98564 KB Output is correct
8 Correct 38 ms 98468 KB Output is correct
9 Correct 38 ms 98524 KB Output is correct
10 Correct 37 ms 98464 KB Output is correct
11 Correct 38 ms 98476 KB Output is correct
12 Correct 39 ms 98468 KB Output is correct
13 Correct 42 ms 98448 KB Output is correct
14 Correct 42 ms 98504 KB Output is correct
15 Correct 47 ms 98536 KB Output is correct
16 Correct 42 ms 98572 KB Output is correct
17 Correct 44 ms 98468 KB Output is correct
18 Correct 48 ms 98452 KB Output is correct
19 Correct 52 ms 98576 KB Output is correct
20 Correct 53 ms 98492 KB Output is correct
21 Correct 61 ms 98460 KB Output is correct
22 Correct 58 ms 98564 KB Output is correct
23 Correct 46 ms 98580 KB Output is correct
24 Correct 45 ms 98580 KB Output is correct
25 Correct 50 ms 98528 KB Output is correct
26 Correct 54 ms 98568 KB Output is correct
27 Correct 53 ms 98504 KB Output is correct
28 Correct 54 ms 98572 KB Output is correct
29 Correct 52 ms 98464 KB Output is correct
30 Correct 56 ms 98600 KB Output is correct
31 Correct 73 ms 98564 KB Output is correct
32 Correct 79 ms 98632 KB Output is correct
33 Correct 59 ms 98576 KB Output is correct
34 Correct 98 ms 98576 KB Output is correct
35 Correct 101 ms 98572 KB Output is correct
36 Correct 84 ms 98572 KB Output is correct
37 Correct 82 ms 98504 KB Output is correct
38 Correct 90 ms 98572 KB Output is correct
39 Correct 94 ms 98576 KB Output is correct
40 Correct 85 ms 98576 KB Output is correct
41 Correct 100 ms 98572 KB Output is correct
42 Correct 86 ms 98532 KB Output is correct
43 Correct 67 ms 98576 KB Output is correct
44 Correct 87 ms 98512 KB Output is correct
45 Correct 105 ms 98572 KB Output is correct
46 Correct 96 ms 98580 KB Output is correct
47 Correct 112 ms 98572 KB Output is correct
48 Correct 74 ms 98588 KB Output is correct
49 Correct 97 ms 98572 KB Output is correct
50 Correct 98 ms 98572 KB Output is correct
51 Correct 107 ms 98700 KB Output is correct
52 Correct 112 ms 98572 KB Output is correct
53 Correct 96 ms 98512 KB Output is correct
54 Correct 95 ms 98572 KB Output is correct
55 Correct 112 ms 98632 KB Output is correct
56 Correct 111 ms 98680 KB Output is correct
57 Correct 92 ms 98580 KB Output is correct
58 Correct 103 ms 98572 KB Output is correct
59 Correct 102 ms 98572 KB Output is correct
60 Correct 98 ms 98572 KB Output is correct