답안 #996038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996038 2024-06-10T07:33:11 Z Tozzyyyy Xylophone (JOI18_xylophone) C++17
100 / 100
86 ms 600 KB
#include<bits/stdc++.h>
#include "xylophone.h"

using namespace std;

void solve(int n) {
	vector<int> a(n+2);
	vector<int> b(n+1) , c(n+1);
	for(int i = 1 ; i < n ; i++){
		b[i] = query(i , i+1);
	}
	for(int i = 2 ; i < n ; i++){
		c[i] = query(i-1 , i+1);
	}
	for(int i = 1 ; i <= n ; i++){
		a[i] = 1;
		a[i+1] = 1 + b[i];
		a[i-1] = b[i-1] + 1;
		for(int j = i + 2 ; j <= n ; j++){
			if(a[j-1] > a[j-2]){
				if(b[j-2] + b[j-1] == c[j-1]) a[j] = a[j-1] + b[j-1];
				else a[j] = a[j-1] - b[j-1];
			}else{
				if(b[j-2] + b[j-1] == c[j-1]) a[j] = a[j-1] - b[j-1];
				else a[j] = a[j-1] + b[j-1];	
			}
		}
		for(int j = i - 2 ; j >= 1 ; j--){
			if(a[j+1] > a[j+2]){
				if(b[j+1] + b[j] == c[j+1]) a[j] = a[j+1] + b[j];
				else a[j] = a[j+1] - b[j];
			}else{
				if(b[j+1] + b[j] == c[j+1]) a[j] = a[j+1] - b[j];
				else a[j] = a[j+1] + b[j];
			}
		}
		vector<int> cnt(n+1);
		int C = 0;
		for(int i = 1 ; i <= n ; i ++){
			if(a[i] < 1 or a[i] > n){
				C=1; break;
			}
			if(cnt[a[i]] == 1){
				C=1; break;
			}
			cnt[a[i]]=1;
		}
		if(C==0){
			for(int i = 1 ; i <= n ; i++) answer(i , a[i]);
			break;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 416 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 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 0 ms 344 KB Output is correct
4 Correct 1 ms 344 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 416 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 8 ms 344 KB Output is correct
19 Correct 10 ms 444 KB Output is correct
20 Correct 13 ms 592 KB Output is correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 10 ms 344 KB Output is correct
23 Correct 9 ms 448 KB Output is correct
24 Correct 13 ms 440 KB Output is correct
25 Correct 11 ms 600 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 9 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 9 ms 448 KB Output is correct
30 Correct 13 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 0 ms 344 KB Output is correct
4 Correct 1 ms 344 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 416 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 8 ms 344 KB Output is correct
19 Correct 10 ms 444 KB Output is correct
20 Correct 13 ms 592 KB Output is correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 10 ms 344 KB Output is correct
23 Correct 9 ms 448 KB Output is correct
24 Correct 13 ms 440 KB Output is correct
25 Correct 11 ms 600 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 9 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 9 ms 448 KB Output is correct
30 Correct 13 ms 344 KB Output is correct
31 Correct 30 ms 436 KB Output is correct
32 Correct 34 ms 344 KB Output is correct
33 Correct 60 ms 464 KB Output is correct
34 Correct 63 ms 472 KB Output is correct
35 Correct 63 ms 468 KB Output is correct
36 Correct 55 ms 468 KB Output is correct
37 Correct 82 ms 468 KB Output is correct
38 Correct 57 ms 592 KB Output is correct
39 Correct 85 ms 472 KB Output is correct
40 Correct 45 ms 472 KB Output is correct
41 Correct 56 ms 488 KB Output is correct
42 Correct 57 ms 344 KB Output is correct
43 Correct 86 ms 488 KB Output is correct
44 Correct 56 ms 468 KB Output is correct
45 Correct 53 ms 344 KB Output is correct
46 Correct 49 ms 344 KB Output is correct
47 Correct 65 ms 468 KB Output is correct
48 Correct 48 ms 488 KB Output is correct
49 Correct 65 ms 596 KB Output is correct
50 Correct 74 ms 592 KB Output is correct
51 Correct 56 ms 472 KB Output is correct
52 Correct 71 ms 592 KB Output is correct
53 Correct 78 ms 468 KB Output is correct
54 Correct 61 ms 468 KB Output is correct
55 Correct 57 ms 596 KB Output is correct
56 Correct 66 ms 596 KB Output is correct
57 Correct 64 ms 592 KB Output is correct
58 Correct 75 ms 344 KB Output is correct
59 Correct 50 ms 468 KB Output is correct
60 Correct 58 ms 468 KB Output is correct