답안 #363309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
363309 2021-02-05T13:09:55 Z teewar Xylophone (JOI18_xylophone) C++14
100 / 100
81 ms 748 KB
    #include "xylophone.h"
    #include <cmath>
    #include <cassert>
    #include <unordered_set>
     
    using namespace std;
     
    void solve(int n) {
    int a[n + 1];
    int l = 1, r = n;
    while(r - l > 1) {
        int m = (l + r) / 2;
        if(query(1, m) >= n - 1) {
            r = m;
        }
        else {
            l = m;
        }
    }
    int mxid = r;
    a[mxid] = n;
    unordered_set<int> free;
    for(int i = 1; i < n; ++i) {
        free.insert(i);
    }
    if(mxid > 1) {
        a[mxid - 1] = a[mxid] - query(mxid - 1, mxid);
        free.erase(a[mxid - 1]);
    }
    if(mxid + 1 <= n) {
        a[mxid + 1] = a[mxid] - query(mxid, mxid + 1);
        free.erase(a[mxid + 1]);
    }
    for(int i = mxid + 2; i <= n; ++i) {
        int p = query(i - 1, i);
        int val1 = a[i - 1] - p;
        int val2 = a[i - 1] + p;
        if(!free.count(val1)) {
            a[i] = val2;
            free.erase(a[i]);
            continue;
        }
        if(!free.count(val2)) {
            a[i] = val1;
            free.erase(a[i]);
            continue;
        }
        int t = query(i - 2, i);
        if(abs(a[i - 1] - a[i - 2]) + p == t) {
            if(a[i - 2] < a[i - 1]) {
                a[i] = val2;
            }
            else {
                a[i] = val1;
            }
        }
        else {
            if(a[i - 2] < a[i - 1]) {
                a[i] = val1;
            }
            else {
                a[i] = val2;
            }
        }
        free.erase(a[i]);
    }
    for(int i = mxid - 2; i >= 1; --i) {
        int p = query(i, i + 1);
        int val1 = a[i + 1] - p;
        int val2 = a[i + 1] + p;
        if(!free.count(val1)) {
            a[i] = val2;
            free.erase(a[i]);
            continue;
        }
        if(!free.count(val2)) { 
            a[i] = val1;
            free.erase(a[i]);
            continue;
        }
        int t = query(i, i + 2);
        if(abs(a[i + 1] - a[i + 2]) + p == t) {
            if(a[i + 1] < a[i + 2]) {
                a[i] = val1;
            }
            else {
                a[i] = val2;
            }
        }
        else {
            if(a[i + 1] < a[i + 2]) {
                a[i] = val2;
            }
            else {
                a[i] = val1;
            }
        }
        free.erase(a[i]);
    }
    for(int i = 1; i <= n; ++i) {
        answer(i, a[i]);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 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 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 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 256 KB Output is correct
17 Correct 8 ms 364 KB Output is correct
18 Correct 12 ms 364 KB Output is correct
19 Correct 11 ms 364 KB Output is correct
20 Correct 13 ms 364 KB Output is correct
21 Correct 12 ms 364 KB Output is correct
22 Correct 12 ms 396 KB Output is correct
23 Correct 9 ms 364 KB Output is correct
24 Correct 11 ms 364 KB Output is correct
25 Correct 11 ms 364 KB Output is correct
26 Correct 11 ms 364 KB Output is correct
27 Correct 12 ms 364 KB Output is correct
28 Correct 12 ms 412 KB Output is correct
29 Correct 10 ms 364 KB Output is correct
30 Correct 12 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 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 256 KB Output is correct
17 Correct 8 ms 364 KB Output is correct
18 Correct 12 ms 364 KB Output is correct
19 Correct 11 ms 364 KB Output is correct
20 Correct 13 ms 364 KB Output is correct
21 Correct 12 ms 364 KB Output is correct
22 Correct 12 ms 396 KB Output is correct
23 Correct 9 ms 364 KB Output is correct
24 Correct 11 ms 364 KB Output is correct
25 Correct 11 ms 364 KB Output is correct
26 Correct 11 ms 364 KB Output is correct
27 Correct 12 ms 364 KB Output is correct
28 Correct 12 ms 412 KB Output is correct
29 Correct 10 ms 364 KB Output is correct
30 Correct 12 ms 364 KB Output is correct
31 Correct 29 ms 364 KB Output is correct
32 Correct 38 ms 492 KB Output is correct
33 Correct 45 ms 620 KB Output is correct
34 Correct 57 ms 620 KB Output is correct
35 Correct 61 ms 640 KB Output is correct
36 Correct 46 ms 492 KB Output is correct
37 Correct 49 ms 620 KB Output is correct
38 Correct 55 ms 620 KB Output is correct
39 Correct 40 ms 624 KB Output is correct
40 Correct 72 ms 596 KB Output is correct
41 Correct 55 ms 620 KB Output is correct
42 Correct 47 ms 620 KB Output is correct
43 Correct 50 ms 620 KB Output is correct
44 Correct 49 ms 620 KB Output is correct
45 Correct 74 ms 492 KB Output is correct
46 Correct 56 ms 748 KB Output is correct
47 Correct 62 ms 620 KB Output is correct
48 Correct 64 ms 620 KB Output is correct
49 Correct 67 ms 620 KB Output is correct
50 Correct 72 ms 620 KB Output is correct
51 Correct 52 ms 620 KB Output is correct
52 Correct 63 ms 620 KB Output is correct
53 Correct 76 ms 620 KB Output is correct
54 Correct 60 ms 620 KB Output is correct
55 Correct 52 ms 620 KB Output is correct
56 Correct 76 ms 748 KB Output is correct
57 Correct 81 ms 620 KB Output is correct
58 Correct 75 ms 620 KB Output is correct
59 Correct 80 ms 620 KB Output is correct
60 Correct 65 ms 620 KB Output is correct