답안 #444878

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444878 2021-07-15T17:26:09 Z Khizri Xylophone (JOI18_xylophone) C++17
100 / 100
86 ms 640 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int arr[5005];
int dp[5005];
map<int,bool>mp;
void solve(int n) {
	int l=1,r=n,k;
	while(l<=r){
		int m=(l+r)/2;
		if(query(m,n)==n-1){
			l=m+1;
			k=m;
		}
		else{
			r=m-1;
		}
	}
	arr[k]=1;
	mp[1]=1;
	for(int i=k+1;i<=n;i++){
		int x=query(i-1,i);
		dp[i-1]=x;
		int a=arr[i-1]+x;
		int b=arr[i-1]-x;
		if(a<=0||a>n||mp[a]){
			arr[i]=b;
			mp[b]=1;
		}
		else if(b<=0||b>n||mp[b]){
			arr[i]=a;
			mp[a]=1;
		}
		else{
			int y=query(i-2,i);
			vector<int>vt{arr[i-2],arr[i-1],a};
			sort(vt.begin(),vt.end());
			if(vt[2]-vt[0]==y){
				arr[i]=a;
				mp[a]=1;
			}
			else{
				arr[i]=b;
				mp[b]=1;
			}
		}
	}
	for(int i=k-1;i>=1;i--){
		int x=query(i,i+1);
		dp[i+1]=x;
		int a=arr[i+1]+x;
		int b=arr[i+1]-x;
		if(a<=0||a>n||mp[a]){
			arr[i]=b;
			mp[b]=1;
		}
		else if(b<=0||b>n||mp[b]){
			arr[i]=a;
			mp[a]=1;
		}
		else{
			int y=query(i,i+2);
			vector<int>vt{arr[i+2],arr[i+1],a};
			sort(vt.begin(),vt.end());
			if(vt[2]-vt[0]==y){
				arr[i]=a;
				mp[a]=1;
			}
			else{
				arr[i]=b;
				mp[b]=1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		answer(i,arr[i]);
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:8:14: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
    8 |  int l=1,r=n,k;
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 2 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 2 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 2 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 2 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
16 Correct 5 ms 200 KB Output is correct
17 Correct 9 ms 316 KB Output is correct
18 Correct 6 ms 300 KB Output is correct
19 Correct 17 ms 324 KB Output is correct
20 Correct 13 ms 348 KB Output is correct
21 Correct 16 ms 328 KB Output is correct
22 Correct 16 ms 328 KB Output is correct
23 Correct 12 ms 332 KB Output is correct
24 Correct 13 ms 328 KB Output is correct
25 Correct 13 ms 328 KB Output is correct
26 Correct 18 ms 328 KB Output is correct
27 Correct 13 ms 328 KB Output is correct
28 Correct 14 ms 332 KB Output is correct
29 Correct 12 ms 324 KB Output is correct
30 Correct 9 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 2 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 2 ms 200 KB Output is correct
14 Correct 2 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
16 Correct 5 ms 200 KB Output is correct
17 Correct 9 ms 316 KB Output is correct
18 Correct 6 ms 300 KB Output is correct
19 Correct 17 ms 324 KB Output is correct
20 Correct 13 ms 348 KB Output is correct
21 Correct 16 ms 328 KB Output is correct
22 Correct 16 ms 328 KB Output is correct
23 Correct 12 ms 332 KB Output is correct
24 Correct 13 ms 328 KB Output is correct
25 Correct 13 ms 328 KB Output is correct
26 Correct 18 ms 328 KB Output is correct
27 Correct 13 ms 328 KB Output is correct
28 Correct 14 ms 332 KB Output is correct
29 Correct 12 ms 324 KB Output is correct
30 Correct 9 ms 328 KB Output is correct
31 Correct 37 ms 328 KB Output is correct
32 Correct 26 ms 376 KB Output is correct
33 Correct 65 ms 448 KB Output is correct
34 Correct 70 ms 576 KB Output is correct
35 Correct 86 ms 480 KB Output is correct
36 Correct 49 ms 576 KB Output is correct
37 Correct 66 ms 576 KB Output is correct
38 Correct 69 ms 584 KB Output is correct
39 Correct 84 ms 572 KB Output is correct
40 Correct 56 ms 548 KB Output is correct
41 Correct 60 ms 464 KB Output is correct
42 Correct 55 ms 556 KB Output is correct
43 Correct 46 ms 472 KB Output is correct
44 Correct 60 ms 580 KB Output is correct
45 Correct 58 ms 548 KB Output is correct
46 Correct 82 ms 640 KB Output is correct
47 Correct 58 ms 572 KB Output is correct
48 Correct 70 ms 576 KB Output is correct
49 Correct 66 ms 576 KB Output is correct
50 Correct 67 ms 480 KB Output is correct
51 Correct 65 ms 576 KB Output is correct
52 Correct 57 ms 556 KB Output is correct
53 Correct 33 ms 496 KB Output is correct
54 Correct 62 ms 576 KB Output is correct
55 Correct 75 ms 564 KB Output is correct
56 Correct 84 ms 576 KB Output is correct
57 Correct 79 ms 480 KB Output is correct
58 Correct 57 ms 576 KB Output is correct
59 Correct 78 ms 480 KB Output is correct
60 Correct 56 ms 472 KB Output is correct