답안 #654528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654528 2022-10-31T15:37:48 Z CDuong Xylophone (JOI18_xylophone) C++14
100 / 100
69 ms 444 KB
#include<bits/stdc++.h>
#include "xylophone.h"

using namespace std;
int a[5005], res[5005];

void solve(int n) {
	memset(a, 0, sizeof(a));
	int l = 1, r = n;
	
	while(l <= r) {
		int mid = (l + r) >> 1;
		int tmp = query(mid, n);
		if(tmp != n - 1) r = mid - 1;
		else l = mid + 1;
	}
	//cout << l << " " << r << endl;
	swap(l, r);
	res[l] = 1;
	a[1] = 1;
	if(l > 1) {
		res[l - 1] = 1 + query(l - 1, l);
		a[res[l - 1]] = 1;
		for(int i = l - 2; i >= 1; --i) {
			int tmp = query(i, i + 1);
			if(res[i + 1] + tmp > n || a[res[i + 1] + tmp]) {
				res[i] = res[i + 1] - tmp;
				a[res[i]] = 1;
				continue;
			}
			if(res[i + 1] - tmp < 1 || a[res[i + 1] - tmp]) {
				res[i] = res[i + 1] + tmp;
				a[res[i]] = 1;
				continue;
			}
			int tmp2 = query(i, i + 2);
			if(tmp2 == tmp || tmp2 == abs(res[i + 1] - res[i + 2])) {
				if(res[i + 1] < res[i + 2]) res[i] = res[i + 1] + tmp;
				else res[i] = res[i + 1] - tmp;
			}
			else {
				if(res[i + 1] < res[i + 2]) res[i] = res[i + 1] - tmp;
				else res[i] = res[i + 1] + tmp;
			}
			a[res[i]] = 1;
		}
	}
	if(l < n) {
		res[l + 1] = 1 + query(l, l + 1);
		a[res[l + 1]] = 1;
		for(int i = l + 2; i <= n; ++i) {
			int tmp = query(i - 1, i);
			if(res[i - 1] + tmp > n || a[res[i - 1] + tmp]) {
				res[i] = res[i - 1] - tmp;
				a[res[i]] = 1;
				continue;
			}
			if(res[i - 1] - tmp < 1 || a[res[i - 1] - tmp]) {
				res[i] = res[i - 1] + tmp;
				a[res[i]] = 1;
				continue;
			}
			int tmp2 = query(i - 2, i);
			if(tmp2 == tmp || tmp2 == abs(res[i - 1] - res[i - 2])) {
				if(res[i - 1] < res[i - 2]) res[i] = res[i - 1] + tmp;
				else res[i] = res[i - 1] - tmp;
			}
			else {
				if(res[i - 1] < res[i - 2]) res[i] = res[i - 1] - tmp;
				else res[i] = res[i - 1] + tmp;
			}
			a[res[i]] = 1;
		}
	}
	//for(int i = 1; i <= n; ++i) cout << i << " " << res[i] << endl;
	for(int i = 1; i <= n; ++i) answer(i, res[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 10 ms 324 KB Output is correct
19 Correct 18 ms 208 KB Output is correct
20 Correct 11 ms 328 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 10 ms 208 KB Output is correct
23 Correct 9 ms 324 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 11 ms 308 KB Output is correct
26 Correct 14 ms 208 KB Output is correct
27 Correct 11 ms 208 KB Output is correct
28 Correct 6 ms 328 KB Output is correct
29 Correct 11 ms 208 KB Output is correct
30 Correct 12 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 6 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 10 ms 324 KB Output is correct
19 Correct 18 ms 208 KB Output is correct
20 Correct 11 ms 328 KB Output is correct
21 Correct 12 ms 208 KB Output is correct
22 Correct 10 ms 208 KB Output is correct
23 Correct 9 ms 324 KB Output is correct
24 Correct 8 ms 208 KB Output is correct
25 Correct 11 ms 308 KB Output is correct
26 Correct 14 ms 208 KB Output is correct
27 Correct 11 ms 208 KB Output is correct
28 Correct 6 ms 328 KB Output is correct
29 Correct 11 ms 208 KB Output is correct
30 Correct 12 ms 208 KB Output is correct
31 Correct 22 ms 312 KB Output is correct
32 Correct 39 ms 312 KB Output is correct
33 Correct 48 ms 316 KB Output is correct
34 Correct 62 ms 316 KB Output is correct
35 Correct 32 ms 320 KB Output is correct
36 Correct 40 ms 312 KB Output is correct
37 Correct 32 ms 320 KB Output is correct
38 Correct 48 ms 316 KB Output is correct
39 Correct 69 ms 324 KB Output is correct
40 Correct 47 ms 324 KB Output is correct
41 Correct 62 ms 316 KB Output is correct
42 Correct 41 ms 328 KB Output is correct
43 Correct 55 ms 432 KB Output is correct
44 Correct 44 ms 320 KB Output is correct
45 Correct 69 ms 308 KB Output is correct
46 Correct 66 ms 312 KB Output is correct
47 Correct 39 ms 324 KB Output is correct
48 Correct 54 ms 316 KB Output is correct
49 Correct 60 ms 316 KB Output is correct
50 Correct 60 ms 316 KB Output is correct
51 Correct 62 ms 320 KB Output is correct
52 Correct 47 ms 340 KB Output is correct
53 Correct 43 ms 316 KB Output is correct
54 Correct 59 ms 432 KB Output is correct
55 Correct 63 ms 316 KB Output is correct
56 Correct 55 ms 444 KB Output is correct
57 Correct 64 ms 320 KB Output is correct
58 Correct 58 ms 328 KB Output is correct
59 Correct 62 ms 312 KB Output is correct
60 Correct 64 ms 312 KB Output is correct