답안 #533982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533982 2022-03-07T18:32:07 Z michao Xylophone (JOI18_xylophone) C++14
100 / 100
101 ms 408 KB
#include "xylophone.h"
using namespace std;
const int MAX=5005;
int ans[MAX];
bool zajety[MAX];
int n;

bool check(int x){
	return x>=1 && x<=n && !zajety[x];
}

void solve(int N){
	n=N;
  int ip=1,ik=n;
  while (ip+1<ik){
		int mid=(ip+ik)>>1;
		if (query(1,mid)==n-1)ik=mid;
		else ip=mid;
  }
  int r=ik;
  ik=r,ip=1;
  while (ip+1<ik){
		int mid=(ip+ik)>>1;
		if (query(mid,r)==n-1)ip=mid;
		else ik=mid;
  }	
  int l=ip;
  ans[l]=1,ans[r]=n;
  zajety[1]=true;
  zajety[n]=true;
  for (int i=l-1;i>=1;i--){
		if (i==l-1){
			int probuj=query(i,l)+ans[l];
			ans[i]=probuj;
			zajety[ans[i]]=true;
		}
		else{
			int q1=query(i,i+1); // poprzedni
			int a=ans[i+2];
			int b=ans[i+1];
			if (!check(b+q1)){
				ans[i]=b-q1;
				continue;
			}
			if (!check(b-q1)){
				ans[i]=b+q1;
				continue;
			}
			int q2=query(i,i+2); // przedpoprzedni
			if (a<b){
				if (check(b+q1) && b+q1==q2+a){
					ans[i]=b+q1;
				}
				else ans[i]=b-q1;
			}
			else{
				if (check(b-q1) && b-q1==a-q2){
					ans[i]=b-q1;
				}
				else ans[i]=b+q1;
			}
		}
		zajety[ans[i]]=true;
  }
  
  
  for (int i=l+1;i<=r-1;i++){
		if (i==l+1){
			int probuj=query(l,i)+ans[l];
			ans[i]=probuj;
			zajety[ans[i]]=true;
		}
		else{
			int q1=query(i-1,i); // poprzedni
			int a=ans[i-2];
			int b=ans[i-1];
			if (!check(b+q1)){
				ans[i]=b-q1;
				continue;
			}
			if (!check(b-q1)){
				ans[i]=b+q1;
				continue;
			}
			int q2=query(i-2,i); // przedpoprzedni
			if (a<b){
				if (check(b+q1) && b+q1==q2+a){
					ans[i]=b+q1;
				}
				else ans[i]=b-q1;
			}
			else{
				if (check(b-q1) && b-q1==a-q2){
					ans[i]=b-q1;
				}
				else ans[i]=b+q1;
			}
		}
		zajety[ans[i]]=true;
  }
  
  for (int i=r+1;i<=n;i++){
		if (i==r+1){
			int probuj=ans[r]-query(r,i);
			ans[i]=probuj;
			zajety[ans[i]]=true;
		}
		else{
			int a=ans[i-2];
			int b=ans[i-1];
			int q1=query(i-1,i); // poprzedni
			if (!check(b+q1)){
				ans[i]=b-q1;
				continue;
			}
			if (!check(b-q1)){
				ans[i]=b+q1;
				continue;
			}
			int q2=query(i-2,i); // przedpoprzedni
			if (a<b){
				if (check(b+q1) && b+q1==q2+a){
					ans[i]=b+q1;
				}
				else ans[i]=b-q1;
			}
			else{
				if (check(b-q1) && b-q1==a-q2){
					ans[i]=b-q1;
				}
				else ans[i]=b+q1;
			}
		}
		zajety[ans[i]]=true;
  }
  for (int i=1;i<=n;i++)answer(i,ans[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 280 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 3 ms 280 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 3 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 1 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 280 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 3 ms 280 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 3 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 1 ms 200 KB Output is correct
16 Correct 3 ms 200 KB Output is correct
17 Correct 7 ms 200 KB Output is correct
18 Correct 13 ms 200 KB Output is correct
19 Correct 18 ms 200 KB Output is correct
20 Correct 14 ms 268 KB Output is correct
21 Correct 16 ms 280 KB Output is correct
22 Correct 15 ms 268 KB Output is correct
23 Correct 10 ms 276 KB Output is correct
24 Correct 5 ms 276 KB Output is correct
25 Correct 14 ms 280 KB Output is correct
26 Correct 16 ms 268 KB Output is correct
27 Correct 7 ms 288 KB Output is correct
28 Correct 15 ms 200 KB Output is correct
29 Correct 15 ms 280 KB Output is correct
30 Correct 16 ms 264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 280 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 3 ms 280 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 2 ms 200 KB Output is correct
7 Correct 3 ms 200 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 3 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 1 ms 200 KB Output is correct
16 Correct 3 ms 200 KB Output is correct
17 Correct 7 ms 200 KB Output is correct
18 Correct 13 ms 200 KB Output is correct
19 Correct 18 ms 200 KB Output is correct
20 Correct 14 ms 268 KB Output is correct
21 Correct 16 ms 280 KB Output is correct
22 Correct 15 ms 268 KB Output is correct
23 Correct 10 ms 276 KB Output is correct
24 Correct 5 ms 276 KB Output is correct
25 Correct 14 ms 280 KB Output is correct
26 Correct 16 ms 268 KB Output is correct
27 Correct 7 ms 288 KB Output is correct
28 Correct 15 ms 200 KB Output is correct
29 Correct 15 ms 280 KB Output is correct
30 Correct 16 ms 264 KB Output is correct
31 Correct 35 ms 272 KB Output is correct
32 Correct 41 ms 284 KB Output is correct
33 Correct 59 ms 280 KB Output is correct
34 Correct 51 ms 292 KB Output is correct
35 Correct 75 ms 380 KB Output is correct
36 Correct 72 ms 268 KB Output is correct
37 Correct 62 ms 280 KB Output is correct
38 Correct 58 ms 200 KB Output is correct
39 Correct 101 ms 276 KB Output is correct
40 Correct 55 ms 328 KB Output is correct
41 Correct 61 ms 276 KB Output is correct
42 Correct 83 ms 408 KB Output is correct
43 Correct 66 ms 200 KB Output is correct
44 Correct 57 ms 276 KB Output is correct
45 Correct 32 ms 284 KB Output is correct
46 Correct 68 ms 284 KB Output is correct
47 Correct 81 ms 392 KB Output is correct
48 Correct 83 ms 296 KB Output is correct
49 Correct 81 ms 296 KB Output is correct
50 Correct 93 ms 284 KB Output is correct
51 Correct 80 ms 280 KB Output is correct
52 Correct 61 ms 276 KB Output is correct
53 Correct 71 ms 268 KB Output is correct
54 Correct 68 ms 272 KB Output is correct
55 Correct 74 ms 276 KB Output is correct
56 Correct 56 ms 284 KB Output is correct
57 Correct 68 ms 280 KB Output is correct
58 Correct 68 ms 200 KB Output is correct
59 Correct 69 ms 280 KB Output is correct
60 Correct 64 ms 268 KB Output is correct