Submission #680563

# Submission time Handle Problem Language Result Execution time Memory
680563 2023-01-11T08:05:00 Z nutella Xylophone (JOI18_xylophone) C++17
100 / 100
71 ms 300 KB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

void solve(int N) {
    vector<bool> was(N + 1);

    int lo = -1, hi = N - 1;
    while (lo + 1 < hi) {
        int mid = lo + hi >> 1;
        if (query(1, mid + 1) == N - 1) {
            hi = mid;
        } else {
            lo = mid;
        }
    }

    answer(hi + 1, N);
    was[N] = true;

    int p = N, pp = -1;
    for (int i = hi - 1; i >= 0; --i) {
        int diff = query(i + 1, i + 2);
        int a;

        if (diff + p > N || was[diff + p]) {
            a = p - diff;
        } else if (p - diff <= 0 || was[p - diff]) {
            a = p + diff;
        } else {
            assert(pp != -1);
            int x = query(i + 1, i + 3);
            if (x == diff) {
                a = pp > p ? p + diff : p - diff;
            } else if (x == abs(pp - p)) {
                a = p + diff < pp ? p + diff : p - diff;
                assert(p < a && a < pp || pp < a && a < p);
            } else {
                a = pp > p ? pp - x : pp + x;
            }
        }

        answer(i + 1, a);
        was[a] = true;
        pp = p;
        p = a;
    }

    p = N;
    pp = -1;
    for (int i = hi + 1; i < N; ++i) {
        int diff = query(i, i + 1);
        int a;

        if (diff + p > N || was[diff + p]) {
            a = p - diff;
        } else if (p - diff <= 0 || was[p - diff]) {
            a = p + diff;
        } else {
            assert(pp != -1);
            int x = query(i - 1, i + 1);
            if (x == diff) {
                a = pp > p ? p + diff : p - diff;
            } else if (x == abs(pp - p)) {
                a = p + diff < pp ? p + diff : p - diff;
                assert(p < a && a < pp || pp < a && a < p);
            } else {
                a = pp > p ? pp - x : pp + x;
            }
        }

        answer(i + 1, a);
        was[a] = true;
        pp = p;
        p = a;
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:11:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   11 |         int mid = lo + hi >> 1;
      |                   ~~~^~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from xylophone.cpp:1:
xylophone.cpp:38:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   38 |                 assert(p < a && a < pp || pp < a && a < p);
      |                        ~~~~~~^~~~~~~~~
xylophone.cpp:67:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   67 |                 assert(p < a && a < pp || pp < a && a < p);
      |                        ~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 268 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 268 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 9 ms 208 KB Output is correct
19 Correct 13 ms 208 KB Output is correct
20 Correct 9 ms 208 KB Output is correct
21 Correct 10 ms 208 KB Output is correct
22 Correct 13 ms 208 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 11 ms 208 KB Output is correct
25 Correct 7 ms 208 KB Output is correct
26 Correct 8 ms 208 KB Output is correct
27 Correct 11 ms 208 KB Output is correct
28 Correct 13 ms 208 KB Output is correct
29 Correct 14 ms 208 KB Output is correct
30 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 268 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 1 ms 292 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 7 ms 208 KB Output is correct
18 Correct 9 ms 208 KB Output is correct
19 Correct 13 ms 208 KB Output is correct
20 Correct 9 ms 208 KB Output is correct
21 Correct 10 ms 208 KB Output is correct
22 Correct 13 ms 208 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 11 ms 208 KB Output is correct
25 Correct 7 ms 208 KB Output is correct
26 Correct 8 ms 208 KB Output is correct
27 Correct 11 ms 208 KB Output is correct
28 Correct 13 ms 208 KB Output is correct
29 Correct 14 ms 208 KB Output is correct
30 Correct 11 ms 208 KB Output is correct
31 Correct 24 ms 240 KB Output is correct
32 Correct 34 ms 208 KB Output is correct
33 Correct 39 ms 208 KB Output is correct
34 Correct 35 ms 292 KB Output is correct
35 Correct 51 ms 208 KB Output is correct
36 Correct 40 ms 208 KB Output is correct
37 Correct 41 ms 300 KB Output is correct
38 Correct 49 ms 208 KB Output is correct
39 Correct 71 ms 208 KB Output is correct
40 Correct 41 ms 208 KB Output is correct
41 Correct 48 ms 208 KB Output is correct
42 Correct 43 ms 208 KB Output is correct
43 Correct 43 ms 208 KB Output is correct
44 Correct 44 ms 208 KB Output is correct
45 Correct 58 ms 208 KB Output is correct
46 Correct 63 ms 208 KB Output is correct
47 Correct 61 ms 208 KB Output is correct
48 Correct 55 ms 208 KB Output is correct
49 Correct 65 ms 208 KB Output is correct
50 Correct 64 ms 208 KB Output is correct
51 Correct 61 ms 208 KB Output is correct
52 Correct 43 ms 208 KB Output is correct
53 Correct 49 ms 208 KB Output is correct
54 Correct 56 ms 208 KB Output is correct
55 Correct 64 ms 208 KB Output is correct
56 Correct 52 ms 208 KB Output is correct
57 Correct 56 ms 208 KB Output is correct
58 Correct 52 ms 208 KB Output is correct
59 Correct 60 ms 208 KB Output is correct
60 Correct 37 ms 208 KB Output is correct