답안 #952174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952174 2024-03-23T08:32:11 Z SmuggingSpun Xylophone (JOI18_xylophone) C++14
100 / 100
100 ms 936 KB
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
void solve(int n){
	vector<vector<int>>save(n + 1, vector<int>(2));
	for(int i = n; i > 2; i--){
		save[i][0] = query(i - 1, i);
		save[i][1] = query(i - 2, i);
	}
	save[2][0] = query(1, 2);
	for(int I = 1; I <= n; I++){
		vector<bool>used(n + 1, false);
		vector<int>ans(n + 1);
		bool is_ans = used[1] = true;
		if(I > (ans[I] = 1)){
			if(used[ans[I - 1] = save[I][0] + 1]){
				continue;
			}
			used[ans[I - 1]] = true;
			for(int i = I - 2; i > 0; i--){
				if(save[i + 2][0] == save[i + 2][1]){
					if(ans[i + 1] > ans[i + 2]){
						ans[i] = ans[i + 1] - save[i + 1][0];
					}
					else{
						ans[i] = ans[i + 1] + save[i + 1][0];
					}
				}
				else if(save[i + 1][0] == save[i + 2][1]){
					if(ans[i + 1] > ans[i + 2]){
						ans[i] = ans[i + 1] - save[i + 1][0];
					}
					else{
						ans[i] = ans[i + 1] + save[i + 1][0];
					}
				}
				else{
					if(ans[i + 2] > ans[i + 1]){
						ans[i] = ans[i + 2] - save[i + 2][1];
					}
					else{
						ans[i] = ans[i + 2] + save[i + 2][1];
					}
				}
				if(ans[i] < 1 || ans[i] > n || used[ans[i]]){
					is_ans = false;
					break;
				}
				used[ans[i]] = true;
			}
		}
		if(is_ans && I < n){
			if(used[ans[I + 1] = save[I + 1][0] + 1]){
				continue;
			}
			used[ans[I + 1]] = true;
			for(int i = I + 2; i <= n; i++){
				if(save[i - 1][0] == save[i][1]){
					if(ans[i - 1] > ans[i - 2]){
						ans[i] = ans[i - 1] - save[i][0];
					}
					else{
						ans[i] = ans[i - 1] + save[i][0];
					}
				}
				else if(save[i][0] == save[i][1]){
					if(ans[i - 1] > ans[i - 2]){
						ans[i] = ans[i - 1] - save[i][0];
					}
					else{
						ans[i] = ans[i - 1] + save[i][0];
					}
				}
				else{
					if(ans[i - 2] > ans[i - 1]){
						ans[i] = ans[i - 2] - save[i][1];
					}
					else{
						ans[i] = ans[i - 2] + save[i][1];
					}
				}
				if(ans[i] < 1 || ans[i] > n || used[ans[i]]){
					is_ans = false;
					break;
				}
				used[ans[i]] = true;
			}
			if(is_ans){
				for(int i = 1; i <= n; i++){
					answer(i, ans[i]);
				}
				return;
			}
		}
	}
}
# 결과 실행 시간 메모리 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 496 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 496 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 6 ms 476 KB Output is correct
19 Correct 10 ms 488 KB Output is correct
20 Correct 8 ms 492 KB Output is correct
21 Correct 8 ms 488 KB Output is correct
22 Correct 7 ms 492 KB Output is correct
23 Correct 9 ms 492 KB Output is correct
24 Correct 10 ms 344 KB Output is correct
25 Correct 10 ms 488 KB Output is correct
26 Correct 9 ms 492 KB Output is correct
27 Correct 7 ms 736 KB Output is correct
28 Correct 7 ms 496 KB Output is correct
29 Correct 8 ms 492 KB Output is correct
30 Correct 9 ms 492 KB Output is correct
# 결과 실행 시간 메모리 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 496 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 6 ms 476 KB Output is correct
19 Correct 10 ms 488 KB Output is correct
20 Correct 8 ms 492 KB Output is correct
21 Correct 8 ms 488 KB Output is correct
22 Correct 7 ms 492 KB Output is correct
23 Correct 9 ms 492 KB Output is correct
24 Correct 10 ms 344 KB Output is correct
25 Correct 10 ms 488 KB Output is correct
26 Correct 9 ms 492 KB Output is correct
27 Correct 7 ms 736 KB Output is correct
28 Correct 7 ms 496 KB Output is correct
29 Correct 8 ms 492 KB Output is correct
30 Correct 9 ms 492 KB Output is correct
31 Correct 15 ms 560 KB Output is correct
32 Correct 23 ms 592 KB Output is correct
33 Correct 37 ms 668 KB Output is correct
34 Correct 59 ms 688 KB Output is correct
35 Correct 39 ms 704 KB Output is correct
36 Correct 49 ms 704 KB Output is correct
37 Correct 100 ms 936 KB Output is correct
38 Correct 45 ms 684 KB Output is correct
39 Correct 52 ms 680 KB Output is correct
40 Correct 36 ms 704 KB Output is correct
41 Correct 49 ms 700 KB Output is correct
42 Correct 49 ms 696 KB Output is correct
43 Correct 80 ms 708 KB Output is correct
44 Correct 50 ms 684 KB Output is correct
45 Correct 63 ms 684 KB Output is correct
46 Correct 56 ms 860 KB Output is correct
47 Correct 44 ms 684 KB Output is correct
48 Correct 45 ms 772 KB Output is correct
49 Correct 47 ms 684 KB Output is correct
50 Correct 50 ms 684 KB Output is correct
51 Correct 57 ms 684 KB Output is correct
52 Correct 49 ms 728 KB Output is correct
53 Correct 57 ms 700 KB Output is correct
54 Correct 44 ms 852 KB Output is correct
55 Correct 45 ms 732 KB Output is correct
56 Correct 44 ms 680 KB Output is correct
57 Correct 42 ms 680 KB Output is correct
58 Correct 46 ms 680 KB Output is correct
59 Correct 48 ms 700 KB Output is correct
60 Correct 52 ms 700 KB Output is correct