답안 #722035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
722035 2023-04-11T10:46:14 Z FatihSolak Xylophone (JOI18_xylophone) C++17
100 / 100
73 ms 436 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int A[5005];
bool vis[5005];
void solve(int N) {

	int l = 1,r = N;
	while(l < r){
		int m = (l + r)/2;
		if(query(1,m) != N-1){
			l = m+1;
		}
		else r = m;
	}
	A[l] = N;
	vis[N] = 1;
	answer(l,N);
	for(int i = l-1; i>=1; i--){
		int dif = query(i,i+1);
		if(A[i+1] + dif > N || vis[A[i+1] + dif]){
			A[i] = A[i+1] - dif;
			vis[A[i]] = 1;
			answer(i,A[i]);
			continue;
		}
		if(A[i+1] - dif < 1 || vis[A[i+1] - dif]){
			A[i] = A[i+1] + dif;
			vis[A[i]] = 1;
			answer(i,A[i]);
			continue;
		}
		for(int j = i + 1;j<=l;j++){
			if(A[j] > A[i+1] + dif){
				int val = query(i,j);
				if(val == A[j] - (A[i+1] - dif)){
					A[i] = (A[i+1] - dif);
				}
				else A[i] = (A[i+1] + dif);
				break;
			}
			if(A[j] < A[i+1] - dif){
				int val = query(i,j);
				if(val == (A[i+1] + dif) - A[j]){
					A[i] = (A[i+1] + dif);
				}
				else A[i] = (A[i+1] - dif);
				break;
			}
		}
		vis[A[i]] = 1;
		answer(i,A[i]);
	}
	for(int i = l+1; i<=N; i++){
		int dif = query(i-1,i);
		if(A[i-1] + dif > N || vis[A[i-1] + dif]){
			A[i] = A[i-1] - dif;
			vis[A[i]] = 1;
			answer(i,A[i]);
			continue;
		}
		if(A[i-1] - dif < 1 || vis[A[i-1] - dif]){
			A[i] = A[i-1] + dif;
			vis[A[i]] = 1;
			answer(i,A[i]);
			continue;
		}
		for(int j = i -1;j>=l;j--){
			if(A[j] > A[i-1] + dif){
				int val = query(j,i);
				if(val == A[j] - (A[i-1] - dif)){
					A[i] = (A[i-1] - dif);
				}
				else A[i] = (A[i-1] + dif);
				break;
			}
			if(A[j] < A[i-1] - dif){
				int val = query(j,i);
				if(val == (A[i-1] + dif) - A[j]){
					A[i] = (A[i-1] + dif);
				}
				else A[i] = (A[i-1] - dif);
				break;
			}
		}
		vis[A[i]] = 1;
		answer(i,A[i]);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 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 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 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 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 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 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 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 3 ms 208 KB Output is correct
17 Correct 10 ms 308 KB Output is correct
18 Correct 11 ms 208 KB Output is correct
19 Correct 13 ms 208 KB Output is correct
20 Correct 15 ms 308 KB Output is correct
21 Correct 13 ms 208 KB Output is correct
22 Correct 12 ms 208 KB Output is correct
23 Correct 10 ms 304 KB Output is correct
24 Correct 10 ms 308 KB Output is correct
25 Correct 8 ms 296 KB Output is correct
26 Correct 13 ms 208 KB Output is correct
27 Correct 11 ms 308 KB Output is correct
28 Correct 11 ms 208 KB Output is correct
29 Correct 13 ms 208 KB Output is correct
30 Correct 9 ms 208 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 208 KB Output is correct
4 Correct 2 ms 296 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 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 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 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 3 ms 208 KB Output is correct
17 Correct 10 ms 308 KB Output is correct
18 Correct 11 ms 208 KB Output is correct
19 Correct 13 ms 208 KB Output is correct
20 Correct 15 ms 308 KB Output is correct
21 Correct 13 ms 208 KB Output is correct
22 Correct 12 ms 208 KB Output is correct
23 Correct 10 ms 304 KB Output is correct
24 Correct 10 ms 308 KB Output is correct
25 Correct 8 ms 296 KB Output is correct
26 Correct 13 ms 208 KB Output is correct
27 Correct 11 ms 308 KB Output is correct
28 Correct 11 ms 208 KB Output is correct
29 Correct 13 ms 208 KB Output is correct
30 Correct 9 ms 208 KB Output is correct
31 Correct 30 ms 208 KB Output is correct
32 Correct 35 ms 296 KB Output is correct
33 Correct 40 ms 424 KB Output is correct
34 Correct 67 ms 316 KB Output is correct
35 Correct 68 ms 208 KB Output is correct
36 Correct 54 ms 208 KB Output is correct
37 Correct 47 ms 308 KB Output is correct
38 Correct 43 ms 296 KB Output is correct
39 Correct 54 ms 308 KB Output is correct
40 Correct 65 ms 296 KB Output is correct
41 Correct 51 ms 208 KB Output is correct
42 Correct 42 ms 292 KB Output is correct
43 Correct 43 ms 308 KB Output is correct
44 Correct 61 ms 296 KB Output is correct
45 Correct 57 ms 436 KB Output is correct
46 Correct 60 ms 316 KB Output is correct
47 Correct 62 ms 292 KB Output is correct
48 Correct 56 ms 328 KB Output is correct
49 Correct 67 ms 308 KB Output is correct
50 Correct 52 ms 308 KB Output is correct
51 Correct 62 ms 208 KB Output is correct
52 Correct 53 ms 208 KB Output is correct
53 Correct 70 ms 208 KB Output is correct
54 Correct 59 ms 304 KB Output is correct
55 Correct 61 ms 292 KB Output is correct
56 Correct 62 ms 308 KB Output is correct
57 Correct 73 ms 300 KB Output is correct
58 Correct 47 ms 304 KB Output is correct
59 Correct 65 ms 308 KB Output is correct
60 Correct 68 ms 308 KB Output is correct