Submission #82739

# Submission time Handle Problem Language Result Execution time Memory
82739 2018-11-01T14:22:11 Z hugo_pm Xylophone (JOI18_xylophone) C++17
100 / 100
77 ms 732 KB
#include "xylophone.h"
#include <vector>
using namespace std;

const int borne = 5005;
int qq[borne][2];
int N;
bool s[borne];

void build()
{
	for (int i = 1; i < N; ++i) {
		qq[i][0] = query(i, i+1);
		if (i+1 != N) {
			qq[i][1] = query(i, i+2);
		}
		if (i != 0) {
			if (qq[i-1][1] == qq[i-1][0] + qq[i][0]) {
				s[i] = s[i-1];
			} else {
				s[i] = 1 - s[i-1];
			}
		}
	}
}

bool essai()
{
	int mm = 1;
	vector<int> ans(N);
	vector<bool> vu(N, false);
	ans[0] = 1;
	for (int i = 1; i < N; ++i) {
		if (s[i]) ans[i] = ans[i-1] + qq[i][0];
		else ans[i] = ans[i-1] - qq[i][0];
		mm = max(ans[i], mm);
	}

	for (int i = 0; i < N; ++i) {
		ans[i] += (N - mm);
		if (ans[i] < 1 || ans[i] > N || vu[ans[i]-1] || (ans[i] == N && vu[0] == false)) return false;
		vu[ans[i]-1] = true;
	}
	for (int i = 0; i < N; ++i) {
		answer(i+1, ans[i]);
	}
	return true;
}

void solve(int locN) {
	N = locN;
	build();
	if (essai()) return;
	for (int i = 0; i <= N; ++i) s[i] = 1 - s[i];
	essai();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 324 KB Output is correct
3 Correct 2 ms 324 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 3 ms 420 KB Output is correct
6 Correct 4 ms 496 KB Output is correct
7 Correct 3 ms 496 KB Output is correct
8 Correct 3 ms 496 KB Output is correct
9 Correct 3 ms 548 KB Output is correct
10 Correct 3 ms 548 KB Output is correct
11 Correct 2 ms 548 KB Output is correct
12 Correct 4 ms 548 KB Output is correct
13 Correct 3 ms 548 KB Output is correct
14 Correct 3 ms 560 KB Output is correct
15 Correct 4 ms 560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 324 KB Output is correct
3 Correct 2 ms 324 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 3 ms 420 KB Output is correct
6 Correct 4 ms 496 KB Output is correct
7 Correct 3 ms 496 KB Output is correct
8 Correct 3 ms 496 KB Output is correct
9 Correct 3 ms 548 KB Output is correct
10 Correct 3 ms 548 KB Output is correct
11 Correct 2 ms 548 KB Output is correct
12 Correct 4 ms 548 KB Output is correct
13 Correct 3 ms 548 KB Output is correct
14 Correct 3 ms 560 KB Output is correct
15 Correct 4 ms 560 KB Output is correct
16 Correct 4 ms 560 KB Output is correct
17 Correct 8 ms 560 KB Output is correct
18 Correct 15 ms 560 KB Output is correct
19 Correct 16 ms 568 KB Output is correct
20 Correct 17 ms 572 KB Output is correct
21 Correct 18 ms 580 KB Output is correct
22 Correct 21 ms 584 KB Output is correct
23 Correct 9 ms 584 KB Output is correct
24 Correct 20 ms 584 KB Output is correct
25 Correct 13 ms 584 KB Output is correct
26 Correct 16 ms 584 KB Output is correct
27 Correct 17 ms 584 KB Output is correct
28 Correct 15 ms 584 KB Output is correct
29 Correct 17 ms 584 KB Output is correct
30 Correct 15 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 324 KB Output is correct
3 Correct 2 ms 324 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 3 ms 420 KB Output is correct
6 Correct 4 ms 496 KB Output is correct
7 Correct 3 ms 496 KB Output is correct
8 Correct 3 ms 496 KB Output is correct
9 Correct 3 ms 548 KB Output is correct
10 Correct 3 ms 548 KB Output is correct
11 Correct 2 ms 548 KB Output is correct
12 Correct 4 ms 548 KB Output is correct
13 Correct 3 ms 548 KB Output is correct
14 Correct 3 ms 560 KB Output is correct
15 Correct 4 ms 560 KB Output is correct
16 Correct 4 ms 560 KB Output is correct
17 Correct 8 ms 560 KB Output is correct
18 Correct 15 ms 560 KB Output is correct
19 Correct 16 ms 568 KB Output is correct
20 Correct 17 ms 572 KB Output is correct
21 Correct 18 ms 580 KB Output is correct
22 Correct 21 ms 584 KB Output is correct
23 Correct 9 ms 584 KB Output is correct
24 Correct 20 ms 584 KB Output is correct
25 Correct 13 ms 584 KB Output is correct
26 Correct 16 ms 584 KB Output is correct
27 Correct 17 ms 584 KB Output is correct
28 Correct 15 ms 584 KB Output is correct
29 Correct 17 ms 584 KB Output is correct
30 Correct 15 ms 588 KB Output is correct
31 Correct 34 ms 588 KB Output is correct
32 Correct 55 ms 588 KB Output is correct
33 Correct 40 ms 588 KB Output is correct
34 Correct 72 ms 596 KB Output is correct
35 Correct 44 ms 596 KB Output is correct
36 Correct 70 ms 724 KB Output is correct
37 Correct 77 ms 724 KB Output is correct
38 Correct 70 ms 724 KB Output is correct
39 Correct 72 ms 724 KB Output is correct
40 Correct 73 ms 732 KB Output is correct
41 Correct 76 ms 732 KB Output is correct
42 Correct 63 ms 732 KB Output is correct
43 Correct 62 ms 732 KB Output is correct
44 Correct 67 ms 732 KB Output is correct
45 Correct 67 ms 732 KB Output is correct
46 Correct 69 ms 732 KB Output is correct
47 Correct 64 ms 732 KB Output is correct
48 Correct 43 ms 732 KB Output is correct
49 Correct 39 ms 732 KB Output is correct
50 Correct 40 ms 732 KB Output is correct
51 Correct 69 ms 732 KB Output is correct
52 Correct 71 ms 732 KB Output is correct
53 Correct 73 ms 732 KB Output is correct
54 Correct 52 ms 732 KB Output is correct
55 Correct 57 ms 732 KB Output is correct
56 Correct 49 ms 732 KB Output is correct
57 Correct 70 ms 732 KB Output is correct
58 Correct 46 ms 732 KB Output is correct
59 Correct 74 ms 732 KB Output is correct
60 Correct 54 ms 732 KB Output is correct