답안 #996175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996175 2024-06-10T08:28:22 Z anHiep Xylophone (JOI18_xylophone) C++14
100 / 100
226 ms 97800 KB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

// static int a[5000];

int a[5004];
int mp[5004][5004];

void solve(int n) {

	// int value = query(1, N);

	// for(int i = 1; i <= N; i++) {
	// 	answer(i, i);
	// }
	int dis = query(1,2);
	// map<pair<int,int>,int> mp;
	mp[1][2]=dis;
	for(int i = 3; i <= n; i++){
		mp[i-1][i] = query(i-1, i);
		mp[i-2][i] = query(i-2, i);
	}
	for(int i = 1; i <= n; i++){
		a[1] = i;
		bool c = 1;
		if(i + dis <= n){
			c = 1;
			a[2] = i + dis;
			vector<int> used(n+1,0);
			used[a[1]] = 1;
			used[a[2]] = 2;

			for(int j = 3; j <= n; j++){
				int x = a[j-1] - mp[j-1][j];
				if(x >= 1 && used[x] == 0){
					if((max({x,a[j-1],a[j-2]})-min({x,a[j-1],a[j-2]})==mp[j-2][j]) && (max(x,a[j-1]) - min(x,a[j-1])==mp[j-1][j])){
						a[j] = x;
						used[x] = j;
						continue;
					}
				}
				x = a[j-1] + mp[j-1][j];
				if(x <= n && used[x] == 0){
					if((max({x,a[j-1],a[j-2]})-min({x,a[j-1],a[j-2]})==mp[j-2][j]) && (max(x,a[j-1]) - min(x,a[j-1])==mp[j-1][j])){
						a[j] = x;
						used[x] = j;
						continue;
					}
				}
				c = 0;
			}
			if(c&&used[1]<used[n]){ 
				
				for(int j = 1;j<=n;j++){
					// cout<<a[j]<<" ";
					answer(j,a[j]);
				}
				// cout<<endl;
				return;
			}
		}
		if(i - dis >= 1){
			c = 1;
			a[2] = i - dis;
			vector<int> used(n+1,0);
			used[a[1]] = 1;
			used[a[2]] = 2;
			for(int j = 3;j<=n;j++){
				int x = a[j-1] - mp[j-1][j];
				if(x >= 1 && used[x] == 0){
					if((max({x,a[j-1],a[j-2]})-min({x,a[j-1],a[j-2]})==mp[j-2][j]) && (max(x,a[j-1]) - min(x,a[j-1])==mp[j-1][j])){
						a[j] = x;
						used[x] = j;
						continue;
					}
				}
				x = a[j-1] + mp[j-1][j];
				if(x <= n && used[x] == 0){
					if((max({x,a[j-1],a[j-2]})-min({x,a[j-1],a[j-2]})==mp[j-2][j]) && (max(x,a[j-1]) - min(x,a[j-1])==mp[j-1][j])){
						a[j] = x;
						used[x] = j;
						continue;
					}
				}
				c = 0;
			}
			if(c&&used[1]<used[n]){
				for(int j = 1;j<=n;j++){
					// cout<<a[j]<<" ";
					answer(j,a[j]);
				}
				// cout<<endl;
				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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2528 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2536 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 2 ms 2392 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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2528 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2536 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 2 ms 2392 KB Output is correct
16 Correct 3 ms 6484 KB Output is correct
17 Correct 8 ms 10840 KB Output is correct
18 Correct 7 ms 16728 KB Output is correct
19 Correct 15 ms 20972 KB Output is correct
20 Correct 21 ms 20824 KB Output is correct
21 Correct 10 ms 20984 KB Output is correct
22 Correct 17 ms 21080 KB Output is correct
23 Correct 12 ms 20956 KB Output is correct
24 Correct 17 ms 21216 KB Output is correct
25 Correct 11 ms 20824 KB Output is correct
26 Correct 16 ms 20956 KB Output is correct
27 Correct 12 ms 20824 KB Output is correct
28 Correct 12 ms 21072 KB Output is correct
29 Correct 13 ms 20824 KB Output is correct
30 Correct 16 ms 20824 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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2528 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2536 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 2 ms 2392 KB Output is correct
16 Correct 3 ms 6484 KB Output is correct
17 Correct 8 ms 10840 KB Output is correct
18 Correct 7 ms 16728 KB Output is correct
19 Correct 15 ms 20972 KB Output is correct
20 Correct 21 ms 20824 KB Output is correct
21 Correct 10 ms 20984 KB Output is correct
22 Correct 17 ms 21080 KB Output is correct
23 Correct 12 ms 20956 KB Output is correct
24 Correct 17 ms 21216 KB Output is correct
25 Correct 11 ms 20824 KB Output is correct
26 Correct 16 ms 20956 KB Output is correct
27 Correct 12 ms 20824 KB Output is correct
28 Correct 12 ms 21072 KB Output is correct
29 Correct 13 ms 20824 KB Output is correct
30 Correct 16 ms 20824 KB Output is correct
31 Correct 23 ms 43540 KB Output is correct
32 Correct 80 ms 62512 KB Output is correct
33 Correct 85 ms 86860 KB Output is correct
34 Correct 125 ms 97196 KB Output is correct
35 Correct 115 ms 97600 KB Output is correct
36 Correct 67 ms 97232 KB Output is correct
37 Correct 130 ms 96988 KB Output is correct
38 Correct 74 ms 97632 KB Output is correct
39 Correct 87 ms 97300 KB Output is correct
40 Correct 113 ms 97196 KB Output is correct
41 Correct 129 ms 97272 KB Output is correct
42 Correct 67 ms 97104 KB Output is correct
43 Correct 145 ms 96980 KB Output is correct
44 Correct 55 ms 97104 KB Output is correct
45 Correct 84 ms 97160 KB Output is correct
46 Correct 212 ms 97144 KB Output is correct
47 Correct 226 ms 97104 KB Output is correct
48 Correct 58 ms 97284 KB Output is correct
49 Correct 174 ms 97108 KB Output is correct
50 Correct 202 ms 97400 KB Output is correct
51 Correct 90 ms 97072 KB Output is correct
52 Correct 91 ms 97520 KB Output is correct
53 Correct 197 ms 97800 KB Output is correct
54 Correct 153 ms 97264 KB Output is correct
55 Correct 163 ms 97056 KB Output is correct
56 Correct 89 ms 96992 KB Output is correct
57 Correct 135 ms 97072 KB Output is correct
58 Correct 113 ms 97104 KB Output is correct
59 Correct 109 ms 97312 KB Output is correct
60 Correct 88 ms 97080 KB Output is correct