답안 #763292

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763292 2023-06-22T07:51:40 Z cheat_when_I_was_young Xylophone (JOI18_xylophone) C++17
47 / 100
196 ms 20492 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);
	int pos = 1;
	for (int i = 1<<12; i > 0; i >>= 1) {
		if (pos + i > n) continue;
		if (query(pos + i, n) == n - 1) pos += i;
	}
	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]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 684 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 656 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 684 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 656 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 4 ms 1224 KB Output is correct
17 Correct 10 ms 2136 KB Output is correct
18 Correct 17 ms 3620 KB Output is correct
19 Correct 24 ms 4348 KB Output is correct
20 Correct 15 ms 4344 KB Output is correct
21 Correct 25 ms 4352 KB Output is correct
22 Correct 19 ms 4304 KB Output is correct
23 Correct 14 ms 4360 KB Output is correct
24 Correct 11 ms 4392 KB Output is correct
25 Correct 25 ms 4268 KB Output is correct
26 Correct 19 ms 4340 KB Output is correct
27 Correct 20 ms 4288 KB Output is correct
28 Correct 22 ms 4284 KB Output is correct
29 Correct 19 ms 4344 KB Output is correct
30 Correct 22 ms 4320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 684 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 688 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 2 ms 656 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 4 ms 1224 KB Output is correct
17 Correct 10 ms 2136 KB Output is correct
18 Correct 17 ms 3620 KB Output is correct
19 Correct 24 ms 4348 KB Output is correct
20 Correct 15 ms 4344 KB Output is correct
21 Correct 25 ms 4352 KB Output is correct
22 Correct 19 ms 4304 KB Output is correct
23 Correct 14 ms 4360 KB Output is correct
24 Correct 11 ms 4392 KB Output is correct
25 Correct 25 ms 4268 KB Output is correct
26 Correct 19 ms 4340 KB Output is correct
27 Correct 20 ms 4288 KB Output is correct
28 Correct 22 ms 4284 KB Output is correct
29 Correct 19 ms 4344 KB Output is correct
30 Correct 22 ms 4320 KB Output is correct
31 Correct 46 ms 9036 KB Output is correct
32 Correct 196 ms 12820 KB Output is correct
33 Correct 157 ms 17984 KB Output is correct
34 Incorrect 87 ms 20492 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -