답안 #262385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262385 2020-08-12T18:33:05 Z Toirov_Sadi Xylophone (JOI18_xylophone) C++17
100 / 100
366 ms 560 KB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

const int N = 5e3 + 7;

int a[N];
int b[N];
int res[N];
bool check(int x, int y, int z, int a, int b){
    if(x <= 0) return 0;
    return (abs(x - y) == a && (max({x, y, z}) - min({x, y, z})) == b);
}
void solve(int N) {
    for(int i = 1; i < N; i ++){
        a[i] = query(i, i + 1);
    }
    for(int i = 1; i < N - 1; i ++){
        b[i] = query(i, i + 2);
    }
    for(int i = 1; i <= N; i ++){
        res[i] = 1;
        int good = 1;
        if(i > 1) res[i - 1] = a[i - 1] + 1;
        res[i + 1] = a[i] + 1;

        for(int j = i - 2; j >= 1; j --){
            int x = res[j + 1] - a[j];
            int y = res[j + 1] + a[j];
            if(check(x, res[j + 1], res[j + 2], a[j], b[j])) res[j] = x;
            else if(check(y, res[j + 1], res[j + 2], a[j], b[j])) res[j] = y;
            else good = 0;
        }

        for(int j = i + 2; j <= N; j ++){
            int x = res[j - 1] - a[j - 1];
            int y = res[j - 1] + a[j - 1];
            if(check(x, res[j - 1], res[j - 2], a[j - 1], b[j - 2])) res[j] = x;
            else if(check(y, res[j - 1], res[j - 2], a[j - 1], b[j - 2])) res[j] = y;
            else good = 0;
        }

        if(good == 1){
            for(int k = 1; k <= N; k ++){
                answer(k, res[k]);
            }
            return;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 0 ms 408 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 0 ms 408 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 16 ms 384 KB Output is correct
19 Correct 16 ms 384 KB Output is correct
20 Correct 25 ms 384 KB Output is correct
21 Correct 23 ms 384 KB Output is correct
22 Correct 18 ms 376 KB Output is correct
23 Correct 19 ms 512 KB Output is correct
24 Correct 24 ms 384 KB Output is correct
25 Correct 21 ms 384 KB Output is correct
26 Correct 24 ms 376 KB Output is correct
27 Correct 26 ms 376 KB Output is correct
28 Correct 20 ms 496 KB Output is correct
29 Correct 12 ms 376 KB Output is correct
30 Correct 20 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 0 ms 408 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 16 ms 384 KB Output is correct
19 Correct 16 ms 384 KB Output is correct
20 Correct 25 ms 384 KB Output is correct
21 Correct 23 ms 384 KB Output is correct
22 Correct 18 ms 376 KB Output is correct
23 Correct 19 ms 512 KB Output is correct
24 Correct 24 ms 384 KB Output is correct
25 Correct 21 ms 384 KB Output is correct
26 Correct 24 ms 376 KB Output is correct
27 Correct 26 ms 376 KB Output is correct
28 Correct 20 ms 496 KB Output is correct
29 Correct 12 ms 376 KB Output is correct
30 Correct 20 ms 504 KB Output is correct
31 Correct 54 ms 508 KB Output is correct
32 Correct 74 ms 372 KB Output is correct
33 Correct 175 ms 520 KB Output is correct
34 Correct 242 ms 508 KB Output is correct
35 Correct 259 ms 504 KB Output is correct
36 Correct 82 ms 504 KB Output is correct
37 Correct 225 ms 428 KB Output is correct
38 Correct 82 ms 504 KB Output is correct
39 Correct 163 ms 428 KB Output is correct
40 Correct 126 ms 504 KB Output is correct
41 Correct 200 ms 380 KB Output is correct
42 Correct 85 ms 464 KB Output is correct
43 Correct 235 ms 376 KB Output is correct
44 Correct 86 ms 376 KB Output is correct
45 Correct 101 ms 560 KB Output is correct
46 Correct 119 ms 376 KB Output is correct
47 Correct 87 ms 376 KB Output is correct
48 Correct 109 ms 376 KB Output is correct
49 Correct 183 ms 376 KB Output is correct
50 Correct 189 ms 376 KB Output is correct
51 Correct 73 ms 532 KB Output is correct
52 Correct 288 ms 504 KB Output is correct
53 Correct 204 ms 508 KB Output is correct
54 Correct 128 ms 504 KB Output is correct
55 Correct 112 ms 376 KB Output is correct
56 Correct 145 ms 376 KB Output is correct
57 Correct 168 ms 376 KB Output is correct
58 Correct 366 ms 504 KB Output is correct
59 Correct 169 ms 376 KB Output is correct
60 Correct 181 ms 504 KB Output is correct