Submission #996017

# Submission time Handle Problem Language Result Execution time Memory
996017 2024-06-10T07:21:05 Z vjudge1 Xylophone (JOI18_xylophone) C++17
100 / 100
154 ms 1192 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;}		
	}
}
# Verdict Execution time Memory 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 1 ms 344 KB Output is correct
5 Correct 1 ms 452 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 1 ms 344 KB Output is correct
14 Correct 2 ms 448 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory 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 1 ms 344 KB Output is correct
5 Correct 1 ms 452 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 1 ms 344 KB Output is correct
14 Correct 2 ms 448 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 12 ms 344 KB Output is correct
20 Correct 13 ms 600 KB Output is correct
21 Correct 12 ms 344 KB Output is correct
22 Correct 12 ms 448 KB Output is correct
23 Correct 9 ms 456 KB Output is correct
24 Correct 11 ms 452 KB Output is correct
25 Correct 11 ms 600 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 11 ms 344 KB Output is correct
28 Correct 11 ms 344 KB Output is correct
29 Correct 12 ms 468 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory 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 1 ms 344 KB Output is correct
5 Correct 1 ms 452 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 1 ms 344 KB Output is correct
14 Correct 2 ms 448 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 5 ms 344 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 12 ms 344 KB Output is correct
20 Correct 13 ms 600 KB Output is correct
21 Correct 12 ms 344 KB Output is correct
22 Correct 12 ms 448 KB Output is correct
23 Correct 9 ms 456 KB Output is correct
24 Correct 11 ms 452 KB Output is correct
25 Correct 11 ms 600 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 11 ms 344 KB Output is correct
28 Correct 11 ms 344 KB Output is correct
29 Correct 12 ms 468 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
31 Correct 21 ms 600 KB Output is correct
32 Correct 63 ms 344 KB Output is correct
33 Correct 63 ms 720 KB Output is correct
34 Correct 117 ms 340 KB Output is correct
35 Correct 111 ms 344 KB Output is correct
36 Correct 39 ms 600 KB Output is correct
37 Correct 108 ms 592 KB Output is correct
38 Correct 57 ms 856 KB Output is correct
39 Correct 58 ms 460 KB Output is correct
40 Correct 85 ms 1192 KB Output is correct
41 Correct 112 ms 704 KB Output is correct
42 Correct 55 ms 592 KB Output is correct
43 Correct 120 ms 444 KB Output is correct
44 Correct 62 ms 688 KB Output is correct
45 Correct 88 ms 600 KB Output is correct
46 Correct 138 ms 604 KB Output is correct
47 Correct 154 ms 708 KB Output is correct
48 Correct 66 ms 856 KB Output is correct
49 Correct 146 ms 592 KB Output is correct
50 Correct 139 ms 712 KB Output is correct
51 Correct 78 ms 600 KB Output is correct
52 Correct 61 ms 600 KB Output is correct
53 Correct 144 ms 344 KB Output is correct
54 Correct 122 ms 344 KB Output is correct
55 Correct 126 ms 592 KB Output is correct
56 Correct 148 ms 344 KB Output is correct
57 Correct 128 ms 448 KB Output is correct
58 Correct 150 ms 1104 KB Output is correct
59 Correct 100 ms 592 KB Output is correct
60 Correct 101 ms 592 KB Output is correct