Submission #230202

# Submission time Handle Problem Language Result Execution time Memory
230202 2020-05-09T04:12:35 Z Nightlight Xylophone (JOI18_xylophone) C++14
100 / 100
80 ms 512 KB
#include "xylophone.h"
#define MIN(i, j) (i < j ? i : j)
#define MAX(i, j) (i > j ? i : j) 
#include <bits/stdc++.h>
 
//static int A[5000];
bool visit[5005];
int ans[5005];
int N;
 
int tanya(int i, int j) {
	return query(MIN(i, j), MAX(i, j));
}
 
void got(int a, int i, int j) {
	int res1, res2;
	res1 = tanya(a, i);
	if(ans[i] + res1 > N || visit[ans[i] + res1] == 1) {
		ans[a] = ans[i] - res1;
		return;
	} 
	if(ans[i] - res1 < 1 || visit[ans[i] - res1] == 1 ) {
		ans[a] = ans[i] + res1;
		return;
	}
	res2 = tanya(a, j);
	if(ans[i] > ans[j]) {
		if(ans[i] + res1 - ans[j] == res2) {
			ans[a] = ans[i] + res1;
		}else ans[a] = ans[i] - res1;
	}else {
		if(ans[j] - ans[i] + res1 == res2) {
			ans[a] = ans[i] - res1;
		}else ans[a] = ans[i] + res1;
	}
}
 
void solve(int n) {
	N = n;
	//binser
	int l = 1, r = N - 1, pos1, last1, last2 = 1;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(tanya(mid, N) == N - 1) {
			l = mid + 1;
			pos1 = mid;
		}else {
			r = mid - 1;
		}
	}
	ans[pos1] = 1;
	if(pos1 > 1) {
		ans[pos1 - 1] = tanya(pos1 - 1, pos1) + 1;
		visit[1] = 1, visit[ans[pos1 - 1]] = 1;
		for(int i = pos1 - 2; i > 0; i--) {
			got(i, i + 1, i + 2);
			visit[ans[i]] = 1;
		}
	}
	ans[pos1 + 1] = tanya(pos1 + 1, pos1) + 1;
	visit[ans[pos1 + 1]] = 1;
	for(int i = pos1 + 2; i <= N; i++) {
		got(i, i - 1, i - 2);
		visit[ans[i]] = 1;
	}
	for(int i = 1; i <= N; i++) {
		answer(i, ans[i]);
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:41:30: warning: unused variable 'last1' [-Wunused-variable]
  int l = 1, r = N - 1, pos1, last1, last2 = 1;
                              ^~~~~
xylophone.cpp:41:37: warning: unused variable 'last2' [-Wunused-variable]
  int l = 1, r = N - 1, pos1, last1, last2 = 1;
                                     ^~~~~
xylophone.cpp:12:14: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Wstrict-overflow]
  return query(MIN(i, j), MAX(i, j));
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:12:14: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow]
  return query(MIN(i, j), MAX(i, j));
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:41:24: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int l = 1, r = N - 1, pos1, last1, last2 = 1;
                        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 288 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 288 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 12 ms 384 KB Output is correct
18 Correct 15 ms 384 KB Output is correct
19 Correct 16 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct
21 Correct 15 ms 384 KB Output is correct
22 Correct 18 ms 376 KB Output is correct
23 Correct 16 ms 380 KB Output is correct
24 Correct 14 ms 384 KB Output is correct
25 Correct 9 ms 380 KB Output is correct
26 Correct 19 ms 384 KB Output is correct
27 Correct 11 ms 376 KB Output is correct
28 Correct 19 ms 384 KB Output is correct
29 Correct 15 ms 384 KB Output is correct
30 Correct 18 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 288 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 8 ms 384 KB Output is correct
17 Correct 12 ms 384 KB Output is correct
18 Correct 15 ms 384 KB Output is correct
19 Correct 16 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct
21 Correct 15 ms 384 KB Output is correct
22 Correct 18 ms 376 KB Output is correct
23 Correct 16 ms 380 KB Output is correct
24 Correct 14 ms 384 KB Output is correct
25 Correct 9 ms 380 KB Output is correct
26 Correct 19 ms 384 KB Output is correct
27 Correct 11 ms 376 KB Output is correct
28 Correct 19 ms 384 KB Output is correct
29 Correct 15 ms 384 KB Output is correct
30 Correct 18 ms 384 KB Output is correct
31 Correct 27 ms 384 KB Output is correct
32 Correct 41 ms 504 KB Output is correct
33 Correct 58 ms 392 KB Output is correct
34 Correct 70 ms 384 KB Output is correct
35 Correct 71 ms 384 KB Output is correct
36 Correct 61 ms 384 KB Output is correct
37 Correct 50 ms 376 KB Output is correct
38 Correct 59 ms 504 KB Output is correct
39 Correct 76 ms 384 KB Output is correct
40 Correct 72 ms 376 KB Output is correct
41 Correct 74 ms 384 KB Output is correct
42 Correct 58 ms 384 KB Output is correct
43 Correct 59 ms 384 KB Output is correct
44 Correct 51 ms 384 KB Output is correct
45 Correct 61 ms 504 KB Output is correct
46 Correct 77 ms 512 KB Output is correct
47 Correct 74 ms 384 KB Output is correct
48 Correct 68 ms 504 KB Output is correct
49 Correct 73 ms 504 KB Output is correct
50 Correct 79 ms 384 KB Output is correct
51 Correct 57 ms 380 KB Output is correct
52 Correct 62 ms 384 KB Output is correct
53 Correct 61 ms 420 KB Output is correct
54 Correct 55 ms 376 KB Output is correct
55 Correct 57 ms 384 KB Output is correct
56 Correct 80 ms 384 KB Output is correct
57 Correct 66 ms 384 KB Output is correct
58 Correct 62 ms 388 KB Output is correct
59 Correct 61 ms 384 KB Output is correct
60 Correct 60 ms 432 KB Output is correct