Submission #763294

# Submission time Handle Problem Language Result Execution time Memory
763294 2023-06-22T07:52:33 Z cheat_when_I_was_young Xylophone (JOI18_xylophone) C++17
100 / 100
705 ms 20732 KB
#include "xylophone.h"
#include "bits/stdc++.h"
using namespace std;
int q[5005][5005], a[5005];
bool check_permutation(int n) {
    bool b[n+1], pos[n+1];
    memset(b, 0, sizeof(b));
    for (int i = 1; i <= n; ++i) if (a[i] <= n) b[a[i]] = 1;
    for (int i = 1; i <= n; ++i) if (!b[i]) return false;
    int pos1, pos2;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == 1) pos1 = i;
        if (a[i] == n) pos2 = i;
    }
    if (pos1 > pos2) return false;
    for (int i = 1; i < n; ++i) if (abs(a[i+1] - a[i]) != q[i][i+1]) return false;
    for (int i = 1; i < n-1; ++i)
        if (max(a[i], max(a[i+1], a[i+2])) - min(a[i], min(a[i+1], a[i+2])) != q[i][i+2]) return false;
    return true;
}
void build_permutation(int n, int x, int y) {
    a[1] = x;
    a[2] = y;
    for (int i = 3; i <= n; ++i) {
		if (q[i-2][i-1] + q[i-1][i] == q[i-2][i]) {
			if (a[i-2] > a[i-1]) a[i] = a[i-1] - q[i-1][i];
			else a[i] = a[i-1] + q[i-1][i];
		} else {
			if (a[i-2] > a[i-1]) a[i] = a[i-1] + q[i-1][i];
			else a[i] = a[i-1] - q[i-1][i];
		}
	}
	int mi = *min_element(a+1, a+n+1) - 1;
	for (int i = 1; i <= n; ++i) a[i] -= mi;
}
void solve(int n) {
	for (int i = 1; i <= n-1; ++i) q[i][i+1] = q[i+1][i] = query(i, i+1);
	for (int i = 1; i <= n-2; ++i) q[i][i+2] = q[i+2][i] = query(i, i+2);
	for (int i = 1; i < n; ++i) {
	    build_permutation(n, 10000, 10000 + i);
	    if (check_permutation(n)) {
	        for (int i = 1; i <= n; ++i) answer(i, a[i]);
	        return;
	    }
	}
	for (int i = 1; i < n; ++i) {
	    build_permutation(n, 10000 + i, 10000);
	    if (check_permutation(n)) {
	        for (int i = 1; i <= n; ++i) answer(i, a[i]);
	        return;
	    }
	}
}

Compilation message

xylophone.cpp: In function 'bool check_permutation(int)':
xylophone.cpp:6:18: warning: unused variable 'pos' [-Wunused-variable]
    6 |     bool b[n+1], pos[n+1];
      |                  ^~~
xylophone.cpp:15:5: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   15 |     if (pos1 > pos2) return false;
      |     ^~
xylophone.cpp:15:5: warning: 'pos2' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 1 ms 692 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 3 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 1 ms 692 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 3 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 4 ms 592 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 10 ms 2208 KB Output is correct
18 Correct 12 ms 3620 KB Output is correct
19 Correct 18 ms 4280 KB Output is correct
20 Correct 14 ms 4368 KB Output is correct
21 Correct 28 ms 4244 KB Output is correct
22 Correct 20 ms 4344 KB Output is correct
23 Correct 20 ms 4336 KB Output is correct
24 Correct 14 ms 4280 KB Output is correct
25 Correct 23 ms 4308 KB Output is correct
26 Correct 18 ms 4280 KB Output is correct
27 Correct 20 ms 4248 KB Output is correct
28 Correct 20 ms 4236 KB Output is correct
29 Correct 26 ms 4468 KB Output is correct
30 Correct 24 ms 4316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 1 ms 692 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 3 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 4 ms 592 KB Output is correct
16 Correct 4 ms 1104 KB Output is correct
17 Correct 10 ms 2208 KB Output is correct
18 Correct 12 ms 3620 KB Output is correct
19 Correct 18 ms 4280 KB Output is correct
20 Correct 14 ms 4368 KB Output is correct
21 Correct 28 ms 4244 KB Output is correct
22 Correct 20 ms 4344 KB Output is correct
23 Correct 20 ms 4336 KB Output is correct
24 Correct 14 ms 4280 KB Output is correct
25 Correct 23 ms 4308 KB Output is correct
26 Correct 18 ms 4280 KB Output is correct
27 Correct 20 ms 4248 KB Output is correct
28 Correct 20 ms 4236 KB Output is correct
29 Correct 26 ms 4468 KB Output is correct
30 Correct 24 ms 4316 KB Output is correct
31 Correct 39 ms 9056 KB Output is correct
32 Correct 163 ms 12820 KB Output is correct
33 Correct 143 ms 17864 KB Output is correct
34 Correct 493 ms 20548 KB Output is correct
35 Correct 429 ms 20572 KB Output is correct
36 Correct 83 ms 20536 KB Output is correct
37 Correct 378 ms 20572 KB Output is correct
38 Correct 412 ms 20536 KB Output is correct
39 Correct 73 ms 20552 KB Output is correct
40 Correct 454 ms 20540 KB Output is correct
41 Correct 527 ms 20656 KB Output is correct
42 Correct 97 ms 20540 KB Output is correct
43 Correct 53 ms 20544 KB Output is correct
44 Correct 415 ms 20484 KB Output is correct
45 Correct 247 ms 20560 KB Output is correct
46 Correct 427 ms 20572 KB Output is correct
47 Correct 85 ms 20732 KB Output is correct
48 Correct 410 ms 20564 KB Output is correct
49 Correct 149 ms 20576 KB Output is correct
50 Correct 430 ms 20560 KB Output is correct
51 Correct 314 ms 20580 KB Output is correct
52 Correct 288 ms 20572 KB Output is correct
53 Correct 454 ms 20696 KB Output is correct
54 Correct 147 ms 20552 KB Output is correct
55 Correct 524 ms 20616 KB Output is correct
56 Correct 683 ms 20572 KB Output is correct
57 Correct 156 ms 20576 KB Output is correct
58 Correct 705 ms 20480 KB Output is correct
59 Correct 503 ms 20680 KB Output is correct
60 Correct 249 ms 20580 KB Output is correct