Submission #255151

# Submission time Handle Problem Language Result Execution time Memory
255151 2020-07-31T12:01:15 Z b00n0rp Xylophone (JOI18_xylophone) C++17
100 / 100
160 ms 636 KB
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i ++)

static int A[5005];

int pos[5005];

void solve(int N) {
	REP(i,N+2) pos[i] = 0;
	int low = 1,high = N-1,mid,start;
	while(low <= high){
		mid = (low+high)/2;
		if(query(mid,N) == N-1){
			start = mid;
			low = mid+1;
		}
		else high = mid-1;
	}
	A[start] = 1;
	pos[1] = start;
	if(start-1){
		A[start-1] = 1+query(start-1,start);
		pos[A[start-1]] = start-1;
	}
	A[start+1] = 1+query(start,start+1);
	pos[A[start+1]] = start+1;
	for(int i = start-2; i >= 1; i --){
		int gg = query(i,i+1);
		bool f1 = (pos[min(A[i+1]+gg,N+1)]==0),f2 = (pos[max(A[i+1]-gg,0)]==0);
		if(f1 and f2){
			int gg2 = query(i,i+2);
			if(max({A[i+1]+gg,A[i+1],A[i+2]})-min({A[i+1]+gg,A[i+1],A[i+2]}) == gg2){
				A[i] = A[i+1]+gg;
			}
			else A[i] = A[i+1]-gg;
		}
		else if(f1) A[i] = A[i+1]+gg;
		else A[i] = A[i+1]-gg;
		pos[A[i]] = i;
	}
	for(int i = start+2; i <= N; i ++){
		int gg = query(i-1,i);
		bool f1 = (pos[min(A[i-1]+gg,N+1)]==0),f2 = (pos[max(A[i-1]-gg,0)]==0);
		if(f1 and f2){
			int gg2 = query(i-2,i);
			if(max({A[i-1]+gg,A[i-1],A[i-2]})-min({A[i-1]+gg,A[i-1],A[i-2]}) == gg2){
				A[i] = A[i-1]+gg;
			}
			else A[i] = A[i-1]-gg;
		}
		else if(f1) A[i] = A[i-1]+gg;
		else A[i] = A[i-1]-gg;
		pos[A[i]] = i;
	}
	REP(i,N) answer(i+1,A[i+1]);
}
 

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:30:10: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
  for(int i = start-2; i >= 1; i --){
          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 7 ms 380 KB Output is correct
18 Correct 13 ms 384 KB Output is correct
19 Correct 24 ms 376 KB Output is correct
20 Correct 13 ms 376 KB Output is correct
21 Correct 18 ms 384 KB Output is correct
22 Correct 14 ms 384 KB Output is correct
23 Correct 14 ms 376 KB Output is correct
24 Correct 14 ms 384 KB Output is correct
25 Correct 13 ms 384 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 13 ms 376 KB Output is correct
28 Correct 14 ms 384 KB Output is correct
29 Correct 15 ms 376 KB Output is correct
30 Correct 15 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 7 ms 380 KB Output is correct
18 Correct 13 ms 384 KB Output is correct
19 Correct 24 ms 376 KB Output is correct
20 Correct 13 ms 376 KB Output is correct
21 Correct 18 ms 384 KB Output is correct
22 Correct 14 ms 384 KB Output is correct
23 Correct 14 ms 376 KB Output is correct
24 Correct 14 ms 384 KB Output is correct
25 Correct 13 ms 384 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 13 ms 376 KB Output is correct
28 Correct 14 ms 384 KB Output is correct
29 Correct 15 ms 376 KB Output is correct
30 Correct 15 ms 384 KB Output is correct
31 Correct 32 ms 384 KB Output is correct
32 Correct 46 ms 392 KB Output is correct
33 Correct 62 ms 384 KB Output is correct
34 Correct 73 ms 384 KB Output is correct
35 Correct 73 ms 384 KB Output is correct
36 Correct 42 ms 384 KB Output is correct
37 Correct 160 ms 384 KB Output is correct
38 Correct 73 ms 400 KB Output is correct
39 Correct 68 ms 408 KB Output is correct
40 Correct 76 ms 384 KB Output is correct
41 Correct 82 ms 400 KB Output is correct
42 Correct 59 ms 404 KB Output is correct
43 Correct 65 ms 384 KB Output is correct
44 Correct 61 ms 384 KB Output is correct
45 Correct 62 ms 400 KB Output is correct
46 Correct 55 ms 384 KB Output is correct
47 Correct 68 ms 408 KB Output is correct
48 Correct 62 ms 396 KB Output is correct
49 Correct 102 ms 384 KB Output is correct
50 Correct 118 ms 396 KB Output is correct
51 Correct 67 ms 536 KB Output is correct
52 Correct 76 ms 392 KB Output is correct
53 Correct 79 ms 636 KB Output is correct
54 Correct 101 ms 404 KB Output is correct
55 Correct 121 ms 384 KB Output is correct
56 Correct 71 ms 404 KB Output is correct
57 Correct 94 ms 392 KB Output is correct
58 Correct 139 ms 400 KB Output is correct
59 Correct 70 ms 396 KB Output is correct
60 Correct 90 ms 384 KB Output is correct