Submission #361196

# Submission time Handle Problem Language Result Execution time Memory
361196 2021-01-28T15:10:41 Z BartolM Xylophone (JOI18_xylophone) C++17
100 / 100
181 ms 748 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

int n;
static int A[5000];
int p[5005], bio[5005];
int dva[5005], tri[5005];

int ok(int x) {
    if (x<=0 || x>n) return 0;
    return !bio[x];
}

int resi(int a, int b, int x, int y) {
    int c=b+x;
    int maxi=max(a, c), mini=min(a, b);
    if (ok(c) && maxi-mini==y) return c;
    c=b-x;
    maxi=max(a, b), mini=min(a, c);
    if (ok(c) && maxi-mini==y) return c;
    return -1;
}

void dodaj(int i, int x) {
    if (i<1 || i>n) return;
    p[i]=x;
    bio[x]=1;
}

void kraj() {
    for (int i=1; i<=n; ++i) answer(i, p[i]);
}

void solve(int N) {
    n=N;
    for (int i=1; i<n; ++i) {
        dva[i]=query(i, i+1);
        if (i+2<=n) tri[i]=query(i, i+2);
    }
    for (int poc=1; poc<=n; ++poc) {
        memset(bio, 0, sizeof bio);
        dodaj(poc, 1);
        dodaj(poc-1, dva[poc-1]+1);
        dodaj(poc+1, dva[poc]+1);
        int fl=1;
        for (int i=poc-2; i>0; --i) {
            int x=resi(p[i+2], p[i+1], dva[i], tri[i]);
            if (!ok(x)) {
                fl=0; break;
            }
            dodaj(i, x);
        }
        for (int i=poc+2; i<=n; ++i) {
            int x=resi(p[i-2], p[i-1], dva[i-1], tri[i-2]);
            if (!ok(x)) {
                fl=0; break;
            }
            dodaj(i, x);
        }
        if (fl) {
            kraj();
            return;
        }
    }
}

Compilation message

xylophone.cpp:7:12: warning: 'A' defined but not used [-Wunused-variable]
    7 | static int A[5000];
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 14 ms 364 KB Output is correct
19 Correct 21 ms 364 KB Output is correct
20 Correct 19 ms 396 KB Output is correct
21 Correct 19 ms 364 KB Output is correct
22 Correct 20 ms 364 KB Output is correct
23 Correct 19 ms 364 KB Output is correct
24 Correct 22 ms 492 KB Output is correct
25 Correct 15 ms 384 KB Output is correct
26 Correct 18 ms 364 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 17 ms 376 KB Output is correct
29 Correct 17 ms 364 KB Output is correct
30 Correct 18 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 14 ms 364 KB Output is correct
19 Correct 21 ms 364 KB Output is correct
20 Correct 19 ms 396 KB Output is correct
21 Correct 19 ms 364 KB Output is correct
22 Correct 20 ms 364 KB Output is correct
23 Correct 19 ms 364 KB Output is correct
24 Correct 22 ms 492 KB Output is correct
25 Correct 15 ms 384 KB Output is correct
26 Correct 18 ms 364 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 17 ms 376 KB Output is correct
29 Correct 17 ms 364 KB Output is correct
30 Correct 18 ms 364 KB Output is correct
31 Correct 44 ms 492 KB Output is correct
32 Correct 59 ms 620 KB Output is correct
33 Correct 90 ms 364 KB Output is correct
34 Correct 86 ms 492 KB Output is correct
35 Correct 90 ms 364 KB Output is correct
36 Correct 136 ms 364 KB Output is correct
37 Correct 155 ms 364 KB Output is correct
38 Correct 82 ms 364 KB Output is correct
39 Correct 93 ms 620 KB Output is correct
40 Correct 98 ms 628 KB Output is correct
41 Correct 94 ms 364 KB Output is correct
42 Correct 84 ms 492 KB Output is correct
43 Correct 181 ms 364 KB Output is correct
44 Correct 52 ms 512 KB Output is correct
45 Correct 127 ms 492 KB Output is correct
46 Correct 96 ms 620 KB Output is correct
47 Correct 91 ms 364 KB Output is correct
48 Correct 71 ms 492 KB Output is correct
49 Correct 61 ms 384 KB Output is correct
50 Correct 110 ms 492 KB Output is correct
51 Correct 109 ms 492 KB Output is correct
52 Correct 85 ms 620 KB Output is correct
53 Correct 125 ms 628 KB Output is correct
54 Correct 99 ms 748 KB Output is correct
55 Correct 107 ms 620 KB Output is correct
56 Correct 90 ms 492 KB Output is correct
57 Correct 107 ms 364 KB Output is correct
58 Correct 121 ms 364 KB Output is correct
59 Correct 108 ms 644 KB Output is correct
60 Correct 86 ms 620 KB Output is correct