답안 #363243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
363243 2021-02-05T11:12:33 Z buyolitsez Xylophone (JOI18_xylophone) C++17
100 / 100
124 ms 768 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

bool Check(int a, int b, int c, int i) {
    if (a == b || b == c || a == c) {return false;}
    if (a > b && b > c) {
        return query(i + 1, i + 3) == a - c;
    }
    if (a > c && c > b) {
        return query(i + 1, i + 3) == a - b;
    }
    if (c > a && a > b) {
        return query(i + 1, i + 3) == c - b;
    }
    if (c > b && b > a) {
        return query(i + 1, i + 3) == c - a;
    }
    if (b > a && a > c) {
        return query(i + 1, i + 3) == b - c;
    }
    if (b > c && c > a) {
        return query(i + 1, i + 3) == b - a;
    }
}

int GetRight(int n, int a, int b, int x, int i) {
    int c1 = b + x, c2 = b - x;
    if (c1 > n) {return c2;}
    if (c2 < 1) {return c1;}
    if (Check(a, b, c1, i)) {
        return c1;
    }
    return c2;
}

int GetLeft(int n, int a, int b, int x, int i) {
    int c1 = a + x, c2 = a - x;
    if (c1 > n) {return c2;}
    if (c2 < 1) {return c1;}
    if (Check(c1, a, b, i)) {
        return c1;
    }
    return c2;
}


void solve(int n) {
    int pos = n - 1;
    int l = 0, r = n;
    while (r - l > 1) {
        int m = l + (r - l) / 2;
        if (query(1, m) == n - 1) {
            r = m;
        } else {
            l = m;
        }
    }
    pos = l;
    vector <int> num(n);
    num[pos] = n;
    if (pos + 1 < n) {
        int x = query(pos + 1, pos + 2);
        num[pos + 1] = n - x;
    }
    vector <vector<int>> cand1(n), cand2(n);
    for (int i = pos + 2; i < n; ++i) {
        int x = query(i, i + 1);
        num[i] = GetRight(n, num[i - 2], num[i - 1], x, i - 2);
    }
    if (pos != 0) {
        int x = query(pos, pos + 1);
        num[pos - 1] = n - x;
    }
    for (int i = pos - 2; i >= 0; --i) {
        int x = query(i + 1, i + 2);
        num[i] = GetLeft(n, num[i + 1], num[i + 2], x, i);
    }
    for(int i = 0; i < n; ++i) {
        answer(i + 1, num[i]);
    }
}

Compilation message

xylophone.cpp: In function 'bool Check(int, int, int, int)':
xylophone.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
   26 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 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 1 ms 376 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 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 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 1 ms 376 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 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 4 ms 364 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 12 ms 364 KB Output is correct
19 Correct 16 ms 492 KB Output is correct
20 Correct 10 ms 376 KB Output is correct
21 Correct 8 ms 376 KB Output is correct
22 Correct 14 ms 364 KB Output is correct
23 Correct 8 ms 364 KB Output is correct
24 Correct 14 ms 364 KB Output is correct
25 Correct 15 ms 364 KB Output is correct
26 Correct 14 ms 364 KB Output is correct
27 Correct 17 ms 364 KB Output is correct
28 Correct 14 ms 364 KB Output is correct
29 Correct 13 ms 364 KB Output is correct
30 Correct 13 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 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 1 ms 376 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 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 4 ms 364 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 12 ms 364 KB Output is correct
19 Correct 16 ms 492 KB Output is correct
20 Correct 10 ms 376 KB Output is correct
21 Correct 8 ms 376 KB Output is correct
22 Correct 14 ms 364 KB Output is correct
23 Correct 8 ms 364 KB Output is correct
24 Correct 14 ms 364 KB Output is correct
25 Correct 15 ms 364 KB Output is correct
26 Correct 14 ms 364 KB Output is correct
27 Correct 17 ms 364 KB Output is correct
28 Correct 14 ms 364 KB Output is correct
29 Correct 13 ms 364 KB Output is correct
30 Correct 13 ms 364 KB Output is correct
31 Correct 31 ms 492 KB Output is correct
32 Correct 43 ms 492 KB Output is correct
33 Correct 57 ms 620 KB Output is correct
34 Correct 62 ms 620 KB Output is correct
35 Correct 68 ms 748 KB Output is correct
36 Correct 61 ms 620 KB Output is correct
37 Correct 57 ms 768 KB Output is correct
38 Correct 82 ms 620 KB Output is correct
39 Correct 109 ms 632 KB Output is correct
40 Correct 95 ms 620 KB Output is correct
41 Correct 96 ms 620 KB Output is correct
42 Correct 55 ms 748 KB Output is correct
43 Correct 48 ms 748 KB Output is correct
44 Correct 67 ms 620 KB Output is correct
45 Correct 124 ms 620 KB Output is correct
46 Correct 81 ms 620 KB Output is correct
47 Correct 49 ms 632 KB Output is correct
48 Correct 70 ms 620 KB Output is correct
49 Correct 105 ms 748 KB Output is correct
50 Correct 67 ms 748 KB Output is correct
51 Correct 64 ms 748 KB Output is correct
52 Correct 93 ms 748 KB Output is correct
53 Correct 79 ms 748 KB Output is correct
54 Correct 66 ms 748 KB Output is correct
55 Correct 48 ms 748 KB Output is correct
56 Correct 66 ms 632 KB Output is correct
57 Correct 88 ms 632 KB Output is correct
58 Correct 89 ms 748 KB Output is correct
59 Correct 73 ms 620 KB Output is correct
60 Correct 70 ms 620 KB Output is correct