Submission #227668

# Submission time Handle Problem Language Result Execution time Memory
227668 2020-04-28T11:32:53 Z muhammad_hokimiyon Xylophone (JOI18_xylophone) C++14
100 / 100
343 ms 632 KB
#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 c[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] );
        }
        for( int j = 1; j <= n; j++ ){
            f &= (b[j] <= n && b[j] >= 1);
            if( !f )break;
            f &= (c[b[j]] == 0);
            c[b[j]] = 1;
        }
        for( int j = 1; j <= n; j++ ){
            c[j] = 0;
        }
        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 time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 14 ms 384 KB Output is correct
18 Correct 20 ms 384 KB Output is correct
19 Correct 24 ms 384 KB Output is correct
20 Correct 27 ms 384 KB Output is correct
21 Correct 30 ms 416 KB Output is correct
22 Correct 24 ms 504 KB Output is correct
23 Correct 22 ms 384 KB Output is correct
24 Correct 33 ms 384 KB Output is correct
25 Correct 23 ms 380 KB Output is correct
26 Correct 18 ms 376 KB Output is correct
27 Correct 31 ms 376 KB Output is correct
28 Correct 25 ms 376 KB Output is correct
29 Correct 24 ms 376 KB Output is correct
30 Correct 25 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 14 ms 384 KB Output is correct
18 Correct 20 ms 384 KB Output is correct
19 Correct 24 ms 384 KB Output is correct
20 Correct 27 ms 384 KB Output is correct
21 Correct 30 ms 416 KB Output is correct
22 Correct 24 ms 504 KB Output is correct
23 Correct 22 ms 384 KB Output is correct
24 Correct 33 ms 384 KB Output is correct
25 Correct 23 ms 380 KB Output is correct
26 Correct 18 ms 376 KB Output is correct
27 Correct 31 ms 376 KB Output is correct
28 Correct 25 ms 376 KB Output is correct
29 Correct 24 ms 376 KB Output is correct
30 Correct 25 ms 384 KB Output is correct
31 Correct 57 ms 376 KB Output is correct
32 Correct 102 ms 376 KB Output is correct
33 Correct 168 ms 384 KB Output is correct
34 Correct 240 ms 376 KB Output is correct
35 Correct 250 ms 376 KB Output is correct
36 Correct 92 ms 376 KB Output is correct
37 Correct 343 ms 508 KB Output is correct
38 Correct 94 ms 504 KB Output is correct
39 Correct 190 ms 376 KB Output is correct
40 Correct 131 ms 384 KB Output is correct
41 Correct 185 ms 500 KB Output is correct
42 Correct 84 ms 384 KB Output is correct
43 Correct 330 ms 376 KB Output is correct
44 Correct 92 ms 384 KB Output is correct
45 Correct 105 ms 376 KB Output is correct
46 Correct 117 ms 376 KB Output is correct
47 Correct 86 ms 384 KB Output is correct
48 Correct 120 ms 384 KB Output is correct
49 Correct 224 ms 376 KB Output is correct
50 Correct 210 ms 504 KB Output is correct
51 Correct 87 ms 376 KB Output is correct
52 Correct 272 ms 384 KB Output is correct
53 Correct 182 ms 504 KB Output is correct
54 Correct 129 ms 632 KB Output is correct
55 Correct 105 ms 480 KB Output is correct
56 Correct 180 ms 504 KB Output is correct
57 Correct 144 ms 384 KB Output is correct
58 Correct 336 ms 380 KB Output is correct
59 Correct 161 ms 376 KB Output is correct
60 Correct 202 ms 396 KB Output is correct