답안 #1051684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051684 2024-08-10T09:00:42 Z fryingduc Xylophone (JOI18_xylophone) C++17
100 / 100
35 ms 600 KB
#include "bits/stdc++.h"
using namespace std;

#ifndef duc_debug
#include "xylophone.h"
#endif
void solve(int n) {
    int res = -1;
    int l = 1, r = n;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(query(1, mid) == n - 1) {
            res = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    vector<int> a(n + 1);
    vector<bool> used(n + 1);
    used[n] = 1;
    a[res] = n;
    if(res < n) a[res + 1] = n - query(res, res + 1), used[a[res + 1]] = 1;
    if(res > 1) a[res - 1] = n - query(res - 1, res), used[a[res - 1]] = 1;
    
    for(int i = res - 2; i; --i) {
        int x = query(i, i + 1);
        int ft = a[i + 1] - x, se = a[i + 1] + x;
        if(ft < 1 || used[ft]) {
            a[i] = se;
            used[se] = 1;
        }
        else if(se > n || used[se]) { 
            a[i] = ft;
            used[ft] = 1;
        }
        else {
            int y = query(i, i + 2);
            if(y == abs(a[i + 1] - a[i + 2])) {
                if(a[i + 1] > a[i + 2]) {
                    a[i] = ft, used[ft] = 1;
                }
                else {
                    a[i] = se, used[se] = 1;
                }
            }
            else {
                if(y == x) {
                    if(a[i + 1] > a[i + 2]) {
                        a[i] = ft, used[ft] = 1;
                    }
                    else {
                        a[i] = se, used[se] = 1;
                    }
                }
                else {
                    if(a[i + 1] < a[i + 2]) {
                        a[i] = a[i + 2] - y, used[a[i]] = 1;
                    }
                    else {
                        a[i] = a[i + 2] + y, used[a[i]] = 1;
                    }
                }
            }
        }
    }
    for(int i = res + 2; i <= n; ++i) {
        int x = query(i - 1, i);
        int ft = a[i - 1] - x, se = a[i - 1] + x;
        if(ft < 1 || used[ft]) {
            a[i] = se;
            used[se] = 1;
        }
        else if(se > n || used[se]) { 
            a[i] = ft;
            used[ft] = 1;
        }
        else {
            int y = query(i - 2, i);
            if(y == abs(a[i - 1] - a[i - 2])) {
                if(a[i - 1] > a[i - 2]) {
                    a[i] = ft, used[ft] = 1;
                }
                else {
                    a[i] = se, used[se] = 1;
                }
            }
            else {
                if(y == x) {
                    if(a[i - 1] > a[i - 2]) {
                        a[i] = ft, used[ft] = 1;
                    }
                    else {
                        a[i] = se, used[se] = 1;
                    }
                }
                else {
                    if(a[i - 1] < a[i - 2]) {
                        a[i] = a[i - 2] - y, used[a[i]] = 1;
                    }
                    else {
                        a[i] = a[i - 2] + y, used[a[i]] = 1;
                    }
                }
            }
        }
    }
    
    for(int i = 1; i <= n; ++i) {
        answer(i, a[i]);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 5 ms 440 KB Output is correct
19 Correct 7 ms 344 KB Output is correct
20 Correct 7 ms 344 KB Output is correct
21 Correct 5 ms 344 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 4 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 8 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 5 ms 440 KB Output is correct
19 Correct 7 ms 344 KB Output is correct
20 Correct 7 ms 344 KB Output is correct
21 Correct 5 ms 344 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 4 ms 344 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 8 ms 344 KB Output is correct
31 Correct 17 ms 344 KB Output is correct
32 Correct 19 ms 344 KB Output is correct
33 Correct 20 ms 344 KB Output is correct
34 Correct 34 ms 592 KB Output is correct
35 Correct 23 ms 344 KB Output is correct
36 Correct 16 ms 592 KB Output is correct
37 Correct 16 ms 444 KB Output is correct
38 Correct 18 ms 344 KB Output is correct
39 Correct 28 ms 432 KB Output is correct
40 Correct 35 ms 444 KB Output is correct
41 Correct 26 ms 436 KB Output is correct
42 Correct 23 ms 428 KB Output is correct
43 Correct 20 ms 428 KB Output is correct
44 Correct 19 ms 452 KB Output is correct
45 Correct 30 ms 432 KB Output is correct
46 Correct 35 ms 428 KB Output is correct
47 Correct 25 ms 344 KB Output is correct
48 Correct 29 ms 344 KB Output is correct
49 Correct 20 ms 592 KB Output is correct
50 Correct 30 ms 436 KB Output is correct
51 Correct 26 ms 428 KB Output is correct
52 Correct 30 ms 432 KB Output is correct
53 Correct 32 ms 436 KB Output is correct
54 Correct 30 ms 432 KB Output is correct
55 Correct 21 ms 344 KB Output is correct
56 Correct 23 ms 600 KB Output is correct
57 Correct 24 ms 452 KB Output is correct
58 Correct 27 ms 428 KB Output is correct
59 Correct 27 ms 436 KB Output is correct
60 Correct 35 ms 344 KB Output is correct