Submission #230201

# Submission time Handle Problem Language Result Execution time Memory
230201 2020-05-09T04:04:32 Z imnoob Xylophone (JOI18_xylophone) C++14
100 / 100
82 ms 516 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 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 256 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 256 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 256 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 256 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 11 ms 256 KB Output is correct
18 Correct 16 ms 384 KB Output is correct
19 Correct 15 ms 384 KB Output is correct
20 Correct 16 ms 512 KB Output is correct
21 Correct 20 ms 376 KB Output is correct
22 Correct 19 ms 256 KB Output is correct
23 Correct 15 ms 384 KB Output is correct
24 Correct 16 ms 384 KB Output is correct
25 Correct 17 ms 384 KB Output is correct
26 Correct 20 ms 384 KB Output is correct
27 Correct 15 ms 384 KB Output is correct
28 Correct 19 ms 384 KB Output is correct
29 Correct 15 ms 384 KB Output is correct
30 Correct 16 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 6 ms 256 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 256 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 6 ms 256 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 11 ms 256 KB Output is correct
18 Correct 16 ms 384 KB Output is correct
19 Correct 15 ms 384 KB Output is correct
20 Correct 16 ms 512 KB Output is correct
21 Correct 20 ms 376 KB Output is correct
22 Correct 19 ms 256 KB Output is correct
23 Correct 15 ms 384 KB Output is correct
24 Correct 16 ms 384 KB Output is correct
25 Correct 17 ms 384 KB Output is correct
26 Correct 20 ms 384 KB Output is correct
27 Correct 15 ms 384 KB Output is correct
28 Correct 19 ms 384 KB Output is correct
29 Correct 15 ms 384 KB Output is correct
30 Correct 16 ms 376 KB Output is correct
31 Correct 29 ms 384 KB Output is correct
32 Correct 36 ms 384 KB Output is correct
33 Correct 64 ms 380 KB Output is correct
34 Correct 56 ms 384 KB Output is correct
35 Correct 65 ms 384 KB Output is correct
36 Correct 52 ms 384 KB Output is correct
37 Correct 46 ms 376 KB Output is correct
38 Correct 47 ms 384 KB Output is correct
39 Correct 54 ms 384 KB Output is correct
40 Correct 74 ms 512 KB Output is correct
41 Correct 50 ms 384 KB Output is correct
42 Correct 49 ms 384 KB Output is correct
43 Correct 61 ms 384 KB Output is correct
44 Correct 52 ms 444 KB Output is correct
45 Correct 61 ms 384 KB Output is correct
46 Correct 82 ms 384 KB Output is correct
47 Correct 78 ms 384 KB Output is correct
48 Correct 69 ms 504 KB Output is correct
49 Correct 57 ms 428 KB Output is correct
50 Correct 61 ms 388 KB Output is correct
51 Correct 35 ms 384 KB Output is correct
52 Correct 71 ms 504 KB Output is correct
53 Correct 64 ms 384 KB Output is correct
54 Correct 54 ms 392 KB Output is correct
55 Correct 80 ms 384 KB Output is correct
56 Correct 59 ms 504 KB Output is correct
57 Correct 66 ms 384 KB Output is correct
58 Correct 53 ms 516 KB Output is correct
59 Correct 73 ms 384 KB Output is correct
60 Correct 66 ms 384 KB Output is correct