Submission #400762

# Submission time Handle Problem Language Result Execution time Memory
400762 2021-05-08T15:57:19 Z timmyfeng Xylophone (JOI18_xylophone) C++17
100 / 100
135 ms 320 KB
#include <bits/stdc++.h>
using namespace std;

#include "xylophone.h"

void solve(int n) {
    vector<int> ans(n + 1);
    ans[2] = ans[1] + query(1, 2);

    for (int i = 3; i <= n; ++i) {
        int x = query(i - 2, i);
        int y = query(i - 1, i);

        if (ans[i - 2] < ans[i - 1]) {
            if (x == ans[i - 1] - ans[i - 2]) {
                ans[i] = ans[i - 1] - y;
            } else if (x == y) {
                ans[i] = ans[i - 1] - y;
            } else {
                ans[i] = ans[i - 1] + y;
            }
        } else {
            if (x == ans[i - 2] - ans[i - 1]) {
                ans[i] = ans[i - 1] + y;
            } else if (x == y) {
                ans[i] = ans[i - 1] + y;
            } else {
                ans[i] = ans[i - 1] - y;
            }
        }
    }

    int offset = *min_element(ans.begin(), ans.end());
    for (int i = 1; i <= n; ++i) {
        ans[i] -= offset - 1;
    }

    if (find(ans.begin(), ans.end(), 1) > find(ans.begin(), ans.end(), n)) {
        for (int i = 1; i <= n; ++i) {
            ans[i] = n + 1 - ans[i];
        }
    }

    for (int i = 1; i <= n; ++i) {
        answer(i, ans[i]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 3 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 4 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 4 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 3 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 3 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 4 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 4 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 3 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 7 ms 200 KB Output is correct
17 Correct 13 ms 204 KB Output is correct
18 Correct 21 ms 200 KB Output is correct
19 Correct 21 ms 200 KB Output is correct
20 Correct 25 ms 280 KB Output is correct
21 Correct 27 ms 200 KB Output is correct
22 Correct 27 ms 200 KB Output is correct
23 Correct 19 ms 304 KB Output is correct
24 Correct 29 ms 200 KB Output is correct
25 Correct 18 ms 200 KB Output is correct
26 Correct 25 ms 200 KB Output is correct
27 Correct 11 ms 300 KB Output is correct
28 Correct 25 ms 200 KB Output is correct
29 Correct 21 ms 200 KB Output is correct
30 Correct 16 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 3 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 4 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 4 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 3 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 7 ms 200 KB Output is correct
17 Correct 13 ms 204 KB Output is correct
18 Correct 21 ms 200 KB Output is correct
19 Correct 21 ms 200 KB Output is correct
20 Correct 25 ms 280 KB Output is correct
21 Correct 27 ms 200 KB Output is correct
22 Correct 27 ms 200 KB Output is correct
23 Correct 19 ms 304 KB Output is correct
24 Correct 29 ms 200 KB Output is correct
25 Correct 18 ms 200 KB Output is correct
26 Correct 25 ms 200 KB Output is correct
27 Correct 11 ms 300 KB Output is correct
28 Correct 25 ms 200 KB Output is correct
29 Correct 21 ms 200 KB Output is correct
30 Correct 16 ms 200 KB Output is correct
31 Correct 52 ms 284 KB Output is correct
32 Correct 82 ms 288 KB Output is correct
33 Correct 100 ms 304 KB Output is correct
34 Correct 91 ms 308 KB Output is correct
35 Correct 130 ms 320 KB Output is correct
36 Correct 104 ms 320 KB Output is correct
37 Correct 82 ms 320 KB Output is correct
38 Correct 116 ms 320 KB Output is correct
39 Correct 101 ms 292 KB Output is correct
40 Correct 84 ms 300 KB Output is correct
41 Correct 86 ms 320 KB Output is correct
42 Correct 91 ms 296 KB Output is correct
43 Correct 127 ms 308 KB Output is correct
44 Correct 134 ms 320 KB Output is correct
45 Correct 129 ms 292 KB Output is correct
46 Correct 122 ms 308 KB Output is correct
47 Correct 93 ms 308 KB Output is correct
48 Correct 86 ms 308 KB Output is correct
49 Correct 80 ms 292 KB Output is correct
50 Correct 85 ms 296 KB Output is correct
51 Correct 48 ms 296 KB Output is correct
52 Correct 135 ms 292 KB Output is correct
53 Correct 112 ms 320 KB Output is correct
54 Correct 127 ms 292 KB Output is correct
55 Correct 103 ms 296 KB Output is correct
56 Correct 89 ms 292 KB Output is correct
57 Correct 51 ms 292 KB Output is correct
58 Correct 67 ms 296 KB Output is correct
59 Correct 96 ms 200 KB Output is correct
60 Correct 104 ms 304 KB Output is correct