답안 #850980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850980 2023-09-18T04:55:35 Z vjudge1 Xylophone (JOI18_xylophone) C++17
100 / 100
41 ms 1972 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n){
	int l=1,r=n-1,mid,f=1;
	while(l<=r){
		mid=(l+r)/2;
		if(query(mid,n)==n-1){
			l=mid+1;
			f=mid;
		}else r=mid-1;
	}
	vector<int>v(n+1);
	map<int,bool>mp;
	for(int i=1;i<=n;i++)mp[i]=1;
	v[f]=1;
	v[f+1]=query(f,f+1)+1;
	if(f>1){
		v[f-1]=query(f-1,f)+1;
	}
	for(auto &i:v)mp[i]=0;
	for(int i=f+2;i<=n;i++){
		int k=query(i-1,i);
		if(!mp[v[i-1]+k]){
			v[i]=v[i-1]-k;
			mp[v[i-1]-k]=0;
			continue;
		}
		if(!mp[v[i-1]-k]){
			v[i]=v[i-1]+k;
			mp[v[i-1]+k]=0;
			continue;
		}
		int kk=query(i-2,i);
		if(kk!=abs(v[i-1]-v[i-2])+k){
			if(v[i-1]>v[i-2]){
				v[i]=v[i-1]-k;
				mp[v[i-1]-k]=0;
			}else{
				v[i]=v[i-1]+k;
				mp[v[i-1]+k]=0;
			}
		}else{
			if(v[i-1]<v[i-2]){
				v[i]=v[i-1]-k;
				mp[v[i-1]-k]=0;
			}else{
				v[i]=v[i-1]+k;
				mp[v[i-1]+k]=0;
			}
		}
	}
	for(int i=f-2;i>=1;i--){
		int k=query(i,i+1);
		if(!mp[v[i+1]+k]){
			v[i]=v[i+1]-k;
			mp[v[i+1]-k]=0;
			continue;
		}
		if(!mp[v[i+1]-k]){
			v[i]=v[i+1]+k;
			mp[v[i+1]+k]=0;
			continue;
		}
		int kk=query(i,i+2);
		if(kk!=abs(v[i+1]-v[i+2])+k){
			if(v[i+1]>v[i+2]){
				v[i]=v[i+1]-k;
				mp[v[i+1]-k]=0;
			}else{
				v[i]=v[i+1]+k;
				mp[v[i+1]+k]=0;
			}
		}else{
			if(v[i+1]<v[i+2]){
				v[i]=v[i+1]-k;
				mp[v[i+1]-k]=0;
			}else{
				v[i]=v[i+1]+k;
				mp[v[i+1]+k]=0;
			}
		}
	}
	for(int i=1;i<=n;i++)answer(i,v[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 432 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 432 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 2 ms 436 KB Output is correct
17 Correct 3 ms 948 KB Output is correct
18 Correct 4 ms 688 KB Output is correct
19 Correct 7 ms 1208 KB Output is correct
20 Correct 7 ms 492 KB Output is correct
21 Correct 8 ms 760 KB Output is correct
22 Correct 6 ms 692 KB Output is correct
23 Correct 4 ms 688 KB Output is correct
24 Correct 4 ms 692 KB Output is correct
25 Correct 4 ms 948 KB Output is correct
26 Correct 5 ms 952 KB Output is correct
27 Correct 6 ms 696 KB Output is correct
28 Correct 6 ms 944 KB Output is correct
29 Correct 5 ms 756 KB Output is correct
30 Correct 5 ms 940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 432 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 432 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 2 ms 436 KB Output is correct
17 Correct 3 ms 948 KB Output is correct
18 Correct 4 ms 688 KB Output is correct
19 Correct 7 ms 1208 KB Output is correct
20 Correct 7 ms 492 KB Output is correct
21 Correct 8 ms 760 KB Output is correct
22 Correct 6 ms 692 KB Output is correct
23 Correct 4 ms 688 KB Output is correct
24 Correct 4 ms 692 KB Output is correct
25 Correct 4 ms 948 KB Output is correct
26 Correct 5 ms 952 KB Output is correct
27 Correct 6 ms 696 KB Output is correct
28 Correct 6 ms 944 KB Output is correct
29 Correct 5 ms 756 KB Output is correct
30 Correct 5 ms 940 KB Output is correct
31 Correct 18 ms 944 KB Output is correct
32 Correct 19 ms 956 KB Output is correct
33 Correct 27 ms 1456 KB Output is correct
34 Correct 29 ms 1184 KB Output is correct
35 Correct 37 ms 1204 KB Output is correct
36 Correct 26 ms 664 KB Output is correct
37 Correct 25 ms 1460 KB Output is correct
38 Correct 26 ms 1260 KB Output is correct
39 Correct 38 ms 1452 KB Output is correct
40 Correct 33 ms 1468 KB Output is correct
41 Correct 37 ms 1716 KB Output is correct
42 Correct 28 ms 664 KB Output is correct
43 Correct 34 ms 1484 KB Output is correct
44 Correct 29 ms 1480 KB Output is correct
45 Correct 40 ms 708 KB Output is correct
46 Correct 38 ms 1204 KB Output is correct
47 Correct 36 ms 928 KB Output is correct
48 Correct 37 ms 1192 KB Output is correct
49 Correct 37 ms 1192 KB Output is correct
50 Correct 33 ms 1208 KB Output is correct
51 Correct 37 ms 1748 KB Output is correct
52 Correct 41 ms 1216 KB Output is correct
53 Correct 33 ms 1476 KB Output is correct
54 Correct 36 ms 1972 KB Output is correct
55 Correct 33 ms 1972 KB Output is correct
56 Correct 40 ms 1732 KB Output is correct
57 Correct 34 ms 1760 KB Output is correct
58 Correct 33 ms 1220 KB Output is correct
59 Correct 31 ms 1476 KB Output is correct
60 Correct 31 ms 1208 KB Output is correct