답안 #996016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996016 2024-06-10T07:20:42 Z BuzzyBeez Xylophone (JOI18_xylophone) C++17
100 / 100
162 ms 1216 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

int d[5008][3];
int a[5008];
int pos[5008];

bool check(int n) {
	fill(pos + 1, pos + n + 1, 0);
	for (int i = 1; i <= n; ++i)
		if (a[i] <= 0 || a[i] > n) return 0;
		else pos[a[i]] = i;
	for (int i = 1; i <= n; ++i) if (!pos[i]) return 0;
	return pos[1] < pos[n];
}

void deduce(int n) {
	for (int i = 3; i <= n; ++i) {
		if (a[i - 2] > a[i - 1]) {
			if (a[i - 2] - a[i - 1] + d[i][1] == d[i][2]) a[i] = a[i - 1] - d[i][1];
			else a[i] = a[i - 1] + d[i][1];
		}
		else {
			if (a[i - 1] - a[i - 2] + d[i][1] == d[i][2]) a[i] = a[i - 1] + d[i][1];
			else a[i] = a[i - 1] - d[i][1];
		}
	}
}

void return_answer(int n) {for (int i = 1; i <= n; ++i) answer(i, a[i]);}

void solve(int n) {
	for (int i = 3; i <= n; ++i) d[i][1] = query(i - 1, i), d[i][2] = query(i - 2, i);
	int d12 = query(1, 2);
	for (a[1] = 1; a[1] <= n; ++a[1]) {
		a[2] = a[1] + d12; deduce(n);
		if (check(n)) {return_answer(n); return;}
		a[2] = a[1] - d12; deduce(n);
		if (check(n)) {return_answer(n); return;}		
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 420 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 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 596 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 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 420 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 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 9 ms 604 KB Output is correct
19 Correct 15 ms 452 KB Output is correct
20 Correct 11 ms 452 KB Output is correct
21 Correct 13 ms 344 KB Output is correct
22 Correct 13 ms 452 KB Output is correct
23 Correct 9 ms 448 KB Output is correct
24 Correct 11 ms 448 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 16 ms 704 KB Output is correct
27 Correct 10 ms 344 KB Output is correct
28 Correct 8 ms 340 KB Output is correct
29 Correct 13 ms 344 KB Output is correct
30 Correct 9 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 420 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 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 9 ms 604 KB Output is correct
19 Correct 15 ms 452 KB Output is correct
20 Correct 11 ms 452 KB Output is correct
21 Correct 13 ms 344 KB Output is correct
22 Correct 13 ms 452 KB Output is correct
23 Correct 9 ms 448 KB Output is correct
24 Correct 11 ms 448 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 16 ms 704 KB Output is correct
27 Correct 10 ms 344 KB Output is correct
28 Correct 8 ms 340 KB Output is correct
29 Correct 13 ms 344 KB Output is correct
30 Correct 9 ms 448 KB Output is correct
31 Correct 22 ms 344 KB Output is correct
32 Correct 63 ms 460 KB Output is correct
33 Correct 75 ms 716 KB Output is correct
34 Correct 105 ms 344 KB Output is correct
35 Correct 122 ms 592 KB Output is correct
36 Correct 49 ms 956 KB Output is correct
37 Correct 113 ms 592 KB Output is correct
38 Correct 43 ms 696 KB Output is correct
39 Correct 74 ms 448 KB Output is correct
40 Correct 78 ms 468 KB Output is correct
41 Correct 115 ms 456 KB Output is correct
42 Correct 69 ms 448 KB Output is correct
43 Correct 109 ms 460 KB Output is correct
44 Correct 42 ms 688 KB Output is correct
45 Correct 95 ms 888 KB Output is correct
46 Correct 157 ms 600 KB Output is correct
47 Correct 162 ms 592 KB Output is correct
48 Correct 70 ms 680 KB Output is correct
49 Correct 150 ms 600 KB Output is correct
50 Correct 148 ms 716 KB Output is correct
51 Correct 84 ms 848 KB Output is correct
52 Correct 61 ms 344 KB Output is correct
53 Correct 138 ms 848 KB Output is correct
54 Correct 135 ms 456 KB Output is correct
55 Correct 140 ms 852 KB Output is correct
56 Correct 149 ms 1216 KB Output is correct
57 Correct 119 ms 716 KB Output is correct
58 Correct 149 ms 600 KB Output is correct
59 Correct 111 ms 592 KB Output is correct
60 Correct 86 ms 344 KB Output is correct