Submission #379391

# Submission time Handle Problem Language Result Execution time Memory
379391 2021-03-18T05:50:05 Z pavement Xylophone (JOI18_xylophone) C++17
100 / 100
144 ms 748 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

int dif[5005], ans[5005], out[5005];

void solve(int N) {
	for (int i = 1; i < N; i++) dif[i] = query(i, i + 1);
	ans[2] = dif[1];
	for (int i = 1; i < N - 1; i++) {
		int x = query(i, i + 2);
		if (dif[i] + dif[i + 1] == x) {
			if (ans[i + 1] > ans[i]) ans[i + 2] = ans[i + 1] + dif[i + 1];
			else ans[i + 2] = ans[i + 1] - dif[i + 1];
		} else {
			if (ans[i + 1] < ans[i]) ans[i + 2] = ans[i + 1] + dif[i + 1];
			else ans[i + 2] = ans[i + 1] - dif[i + 1];
		}
	}
	int curs = 1e9, smal = -1, curm = -1e9, big = -1;
	for (int i = 1; i <= N; i++) {
		if (ans[i] < curs) {
			curs = ans[i];
			smal = i;
		}
		if (ans[i] > curm) {
			curm = ans[i];
			big = i;
		}
	}
	if (smal > big) {
		for (int i = 1; i <= N; i++) ans[i] = -ans[i];
		swap(smal, big);
	}
	out[1] = 1 - ans[smal];
	for (int i = 2; i <= N; i++)
		out[i] = out[1] + ans[i];
	for (int i = 1; i <= N; i++)
		answer(i, out[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 4 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 4 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 21 ms 364 KB Output is correct
19 Correct 23 ms 364 KB Output is correct
20 Correct 24 ms 392 KB Output is correct
21 Correct 26 ms 364 KB Output is correct
22 Correct 20 ms 364 KB Output is correct
23 Correct 26 ms 364 KB Output is correct
24 Correct 25 ms 392 KB Output is correct
25 Correct 16 ms 364 KB Output is correct
26 Correct 26 ms 512 KB Output is correct
27 Correct 26 ms 364 KB Output is correct
28 Correct 30 ms 384 KB Output is correct
29 Correct 26 ms 364 KB Output is correct
30 Correct 25 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 3 ms 364 KB Output is correct
8 Correct 4 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 21 ms 364 KB Output is correct
19 Correct 23 ms 364 KB Output is correct
20 Correct 24 ms 392 KB Output is correct
21 Correct 26 ms 364 KB Output is correct
22 Correct 20 ms 364 KB Output is correct
23 Correct 26 ms 364 KB Output is correct
24 Correct 25 ms 392 KB Output is correct
25 Correct 16 ms 364 KB Output is correct
26 Correct 26 ms 512 KB Output is correct
27 Correct 26 ms 364 KB Output is correct
28 Correct 30 ms 384 KB Output is correct
29 Correct 26 ms 364 KB Output is correct
30 Correct 25 ms 384 KB Output is correct
31 Correct 44 ms 364 KB Output is correct
32 Correct 71 ms 492 KB Output is correct
33 Correct 72 ms 364 KB Output is correct
34 Correct 64 ms 388 KB Output is correct
35 Correct 90 ms 364 KB Output is correct
36 Correct 90 ms 500 KB Output is correct
37 Correct 90 ms 364 KB Output is correct
38 Correct 89 ms 364 KB Output is correct
39 Correct 99 ms 364 KB Output is correct
40 Correct 116 ms 364 KB Output is correct
41 Correct 113 ms 492 KB Output is correct
42 Correct 87 ms 396 KB Output is correct
43 Correct 128 ms 364 KB Output is correct
44 Correct 89 ms 620 KB Output is correct
45 Correct 144 ms 364 KB Output is correct
46 Correct 139 ms 364 KB Output is correct
47 Correct 100 ms 388 KB Output is correct
48 Correct 91 ms 492 KB Output is correct
49 Correct 124 ms 364 KB Output is correct
50 Correct 91 ms 364 KB Output is correct
51 Correct 135 ms 512 KB Output is correct
52 Correct 108 ms 492 KB Output is correct
53 Correct 64 ms 748 KB Output is correct
54 Correct 110 ms 524 KB Output is correct
55 Correct 111 ms 492 KB Output is correct
56 Correct 52 ms 380 KB Output is correct
57 Correct 118 ms 364 KB Output is correct
58 Correct 127 ms 528 KB Output is correct
59 Correct 111 ms 748 KB Output is correct
60 Correct 117 ms 544 KB Output is correct