Submission #894607

# Submission time Handle Problem Language Result Execution time Memory
894607 2023-12-28T14:20:29 Z lunaTu Xylophone (JOI18_xylophone) C++17
100 / 100
64 ms 760 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#include "xylophone.h"
typedef long long ll;
using namespace std;

bool solve2(int n, vector<pair<int, int>>& g) {
    map<int, int> d;

    vector<int> a(n + 1);

    a[1] = 0;
    a[2] = g[2].ss;

    d[0] = 1;
    d[a[2]] = 2;

    for (int i = 3; i <= n; i++) {
        int x = g[i].ff, y = g[i].ss;

        int r = abs(a[i - 2] - a[i - 1]);

        if (a[i - 2] < a[i - 1]) {
            if (x != r  && x != y) a[i] = a[i - 2] + x;
            else a[i] = a[i - 1] - y;
        }
        else {
            if (x != r && x != y) a[i] = a[i - 2] - x;
            else a[i] = a[i - 1] + y;
        }

        if (d[a[i]]) return 0;

        d[a[i]] = i;
    }

    if ((*d.begin()).ss > (*d.rbegin()).ss) return 0;

    int i = 1;
    for (auto [x, y] : d) {
        answer(y, i);
        i++;
    }

    return 1;
}

void solve(int N) {
    vector<pair<int, int>> g(N + 1);
    g[2].ss = query(1, 2);

    for (int i = 3; i <= N; i++) {
        g[i].ff = query(i - 2, i);
        g[i].ss = query(i - 1, i);
    }

    if (solve2(N, g)) return;

    g[2].ss *= -1;

    if (solve2(N, g)) return;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 1 ms 440 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 1 ms 440 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
16 Correct 3 ms 432 KB Output is correct
17 Correct 5 ms 440 KB Output is correct
18 Correct 6 ms 444 KB Output is correct
19 Correct 8 ms 448 KB Output is correct
20 Correct 8 ms 440 KB Output is correct
21 Correct 10 ms 444 KB Output is correct
22 Correct 10 ms 440 KB Output is correct
23 Correct 13 ms 424 KB Output is correct
24 Correct 13 ms 448 KB Output is correct
25 Correct 9 ms 440 KB Output is correct
26 Correct 8 ms 440 KB Output is correct
27 Correct 9 ms 444 KB Output is correct
28 Correct 8 ms 440 KB Output is correct
29 Correct 8 ms 448 KB Output is correct
30 Correct 10 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 440 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 1 ms 440 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
16 Correct 3 ms 432 KB Output is correct
17 Correct 5 ms 440 KB Output is correct
18 Correct 6 ms 444 KB Output is correct
19 Correct 8 ms 448 KB Output is correct
20 Correct 8 ms 440 KB Output is correct
21 Correct 10 ms 444 KB Output is correct
22 Correct 10 ms 440 KB Output is correct
23 Correct 13 ms 424 KB Output is correct
24 Correct 13 ms 448 KB Output is correct
25 Correct 9 ms 440 KB Output is correct
26 Correct 8 ms 440 KB Output is correct
27 Correct 9 ms 444 KB Output is correct
28 Correct 8 ms 440 KB Output is correct
29 Correct 8 ms 448 KB Output is correct
30 Correct 10 ms 444 KB Output is correct
31 Correct 18 ms 444 KB Output is correct
32 Correct 25 ms 436 KB Output is correct
33 Correct 41 ms 696 KB Output is correct
34 Correct 46 ms 708 KB Output is correct
35 Correct 57 ms 704 KB Output is correct
36 Correct 54 ms 704 KB Output is correct
37 Correct 50 ms 708 KB Output is correct
38 Correct 47 ms 760 KB Output is correct
39 Correct 49 ms 744 KB Output is correct
40 Correct 50 ms 724 KB Output is correct
41 Correct 52 ms 704 KB Output is correct
42 Correct 46 ms 712 KB Output is correct
43 Correct 42 ms 724 KB Output is correct
44 Correct 43 ms 720 KB Output is correct
45 Correct 64 ms 708 KB Output is correct
46 Correct 48 ms 712 KB Output is correct
47 Correct 44 ms 708 KB Output is correct
48 Correct 53 ms 704 KB Output is correct
49 Correct 50 ms 732 KB Output is correct
50 Correct 53 ms 720 KB Output is correct
51 Correct 48 ms 712 KB Output is correct
52 Correct 50 ms 704 KB Output is correct
53 Correct 44 ms 708 KB Output is correct
54 Correct 45 ms 704 KB Output is correct
55 Correct 48 ms 708 KB Output is correct
56 Correct 48 ms 760 KB Output is correct
57 Correct 50 ms 708 KB Output is correct
58 Correct 60 ms 708 KB Output is correct
59 Correct 56 ms 712 KB Output is correct
60 Correct 41 ms 720 KB Output is correct