답안 #759418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
759418 2023-06-16T09:25:57 Z Nika533 Xylophone (JOI18_xylophone) C++14
100 / 100
54 ms 304 KB
#include "xylophone.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
using namespace std;
int n,m,T,k;
void solve (int n) {
	int ind1;
	int l=1;
	int r=n;
	while (l<=r) {
		int mid=(l+r)/2;
		
		int x=query(mid,n);
		
		if (x==n-1) {
			ind1=mid;
			l=mid+1;
		}
		else {
			r=mid-1;
		}
	}
	int indn;
	l=ind1+1;
	r=n;
	while (l<=r) {
		int mid=(l+r)/2;
		
		int x=query(ind1,mid); 
		
		if (x==n-1) {
			indn=mid;
			r=mid-1;
		}
		else {
			l=mid+1;
		}
	}
	
	vector<bool> fix(n+1,0);
	vector<int> arr(n+1,0);
	
	answer(ind1,1);
	answer(indn,n);
	
	fix[1]=1;
	arr[ind1]=1;
	fix[n]=1;
	arr[indn]=n;
	
	for (int i=ind1-1; i>=1; i--) {
		
		int x=query(i,i+1);
		
		int val1=arr[i+1]-x;
		int val2=arr[i+1]+x;
		
		if (val1<1 || fix[val1]==1) {
			arr[i]=val2;
			fix[val2]=1;
			
			answer(i,val2);
		}
		else if (val2>n || fix[val2]==1) {
			arr[i]=val1;
			fix[val1]=1;
			
			answer(i,val1);
		}
		else {
			
			int y=query(i,i+2);
			
			int val;
			
			int mx=max(val1,max(arr[i+1],arr[i+2]));
			int mn=min(val1,min(arr[i+1],arr[i+2]));
			
			if (mx-mn==y) {
				val=val1;
			}
			else {
				val=val2;
			}
			
			arr[i]=val;
			fix[val]=1;
			
			answer(i,val);
		}
	}
	for (int i=indn-1; i>ind1; i--) {
		
		int x=query(i,i+1);
		
		int val1=arr[i+1]-x;
		int val2=arr[i+1]+x;
		
		if (val1<1 || fix[val1]==1) {
			arr[i]=val2;
			fix[val2]=1;
			
			answer(i,val2);
		}
		else if (val2>n || fix[val2]==1) {
			arr[i]=val1;
			fix[val1]=1;
			
			answer(i,val1);
		}
		else {
			
			int y=query(i,i+2);
			
			int val;
			
			int mx=max(val1,max(arr[i+1],arr[i+2]));
			int mn=min(val1,min(arr[i+1],arr[i+2]));
			
			if (mx-mn==y) {
				val=val1;
			}
			else {
				val=val2;
			}
			
			arr[i]=val;
			fix[val]=1;
			
			answer(i,val);
		}
	}
	for (int i=indn+1; i<=n; i++) {
		int x=query(i-1,i);
		
		int val1=arr[i-1]-x;
		int val2=arr[i-1]+x;
		
		if (val1<1 || fix[val1]==1) {
			arr[i]=val2;
			fix[val2]=1;
			
			answer(i,val2);
		}
		else if (val2>n || fix[val2]==1) {
			arr[i]=val1;
			fix[val1]=1;
			
			answer(i,val1);
		}
		else {
			int y=query(i-2,i);
			
			int val;
			
			int mx=max(val1,max(arr[i-1],arr[i-2]));
			int mn=min(val1,min(arr[i-1],arr[i-2]));
			
			if (mx-mn==y) {
				val=val1;
			}
			else {
				val=val2;
			}
			
			arr[i]=val;
			fix[val]=1;
			
			answer(i,val);
		}
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:29:3: warning: 'ind1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |  l=ind1+1;
      |  ~^~~~~~~
xylophone.cpp:138:11: warning: 'indn' may be used uninitialized in this function [-Wmaybe-uninitialized]
  138 |  for (int i=indn+1; i<=n; i++) {
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 7 ms 208 KB Output is correct
19 Correct 8 ms 300 KB Output is correct
20 Correct 10 ms 208 KB Output is correct
21 Correct 7 ms 208 KB Output is correct
22 Correct 6 ms 208 KB Output is correct
23 Correct 5 ms 208 KB Output is correct
24 Correct 6 ms 208 KB Output is correct
25 Correct 6 ms 208 KB Output is correct
26 Correct 9 ms 208 KB Output is correct
27 Correct 8 ms 304 KB Output is correct
28 Correct 8 ms 208 KB Output is correct
29 Correct 8 ms 208 KB Output is correct
30 Correct 8 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 7 ms 208 KB Output is correct
19 Correct 8 ms 300 KB Output is correct
20 Correct 10 ms 208 KB Output is correct
21 Correct 7 ms 208 KB Output is correct
22 Correct 6 ms 208 KB Output is correct
23 Correct 5 ms 208 KB Output is correct
24 Correct 6 ms 208 KB Output is correct
25 Correct 6 ms 208 KB Output is correct
26 Correct 9 ms 208 KB Output is correct
27 Correct 8 ms 304 KB Output is correct
28 Correct 8 ms 208 KB Output is correct
29 Correct 8 ms 208 KB Output is correct
30 Correct 8 ms 208 KB Output is correct
31 Correct 16 ms 208 KB Output is correct
32 Correct 24 ms 228 KB Output is correct
33 Correct 35 ms 292 KB Output is correct
34 Correct 40 ms 208 KB Output is correct
35 Correct 40 ms 208 KB Output is correct
36 Correct 34 ms 208 KB Output is correct
37 Correct 39 ms 208 KB Output is correct
38 Correct 22 ms 208 KB Output is correct
39 Correct 41 ms 208 KB Output is correct
40 Correct 39 ms 208 KB Output is correct
41 Correct 39 ms 292 KB Output is correct
42 Correct 30 ms 208 KB Output is correct
43 Correct 36 ms 208 KB Output is correct
44 Correct 32 ms 208 KB Output is correct
45 Correct 40 ms 208 KB Output is correct
46 Correct 36 ms 208 KB Output is correct
47 Correct 42 ms 208 KB Output is correct
48 Correct 45 ms 208 KB Output is correct
49 Correct 40 ms 208 KB Output is correct
50 Correct 38 ms 292 KB Output is correct
51 Correct 41 ms 208 KB Output is correct
52 Correct 39 ms 208 KB Output is correct
53 Correct 38 ms 288 KB Output is correct
54 Correct 38 ms 208 KB Output is correct
55 Correct 39 ms 300 KB Output is correct
56 Correct 31 ms 208 KB Output is correct
57 Correct 38 ms 208 KB Output is correct
58 Correct 39 ms 208 KB Output is correct
59 Correct 40 ms 208 KB Output is correct
60 Correct 54 ms 208 KB Output is correct