Submission #66557

# Submission time Handle Problem Language Result Execution time Memory
66557 2018-08-11T12:01:49 Z zadrga Xylophone (JOI18_xylophone) C++14
100 / 100
81 ms 724 KB
/*
Idea:
- http://s3-ap-northeast-1.amazonaws.com/data.cms.ioi-jp.org/open-2018/2018-open-xylophone-sol-en.pdf
*/

#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (int) (2 * 1e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 5111

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

int ret[maxn];
bool used[maxn];

void solve(int N){
	int l = 2, d = N, max_ind = -1;
	while(l <= d){
		int mid = (l + d) / 2;
		int val = query(1, mid);
		if(val == N - 1){
			max_ind = mid;
			d = mid - 1;
		}
		else
			l = mid + 1; 
	}

	ret[max_ind] = N;
	used[N] = 1;

	if(max_ind + 1 <= N){
		int cur = query(max_ind, max_ind + 1);
		ret[max_ind + 1] = N - cur;
		used[N - cur] = 1;
	}

	if(max_ind - 1 >= 1){
		int cur = query(max_ind - 1, max_ind);
		ret[max_ind - 1] = N - cur;
		used[N - cur] = 1;
	}

	for(int i = max_ind + 2; i <= N; i++){
		int diff = query(i - 1, i);
		int opt1 = ret[i - 1] + diff;
		int opt2 = ret[i - 1] - diff;

		if(opt1 < 1 || opt1 > N || used[opt1]){
			ret[i] = opt2;
			used[ret[i]] = 1;
			continue;
		}

		if(opt2 < 1 || opt2 > N || used[opt2]){
			ret[i] = opt1;
			used[ret[i]] = 1;
			continue;
		}

		int updown = query(i - 2, i);
		if(max(ret[i - 2], max(ret[i - 1], opt1)) - min(ret[i - 2], min(ret[i - 1], opt1)) == updown){
			ret[i] = opt1;
		}
		else
			ret[i] = opt2;

		used[ret[i]] = 1;
	}

	for(int i = max_ind - 2; i >= 1; i--){
		int diff = query(i, i + 1);
		int opt1 = ret[i + 1] + diff;
		int opt2 = ret[i + 1] - diff;

		if(opt1 < 1 || opt1 > N || used[opt1]){
			ret[i] = opt2;
			used[ret[i]] = 1;
			continue;
		}

		if(opt2 < 1 || opt2 > N || used[opt2]){
			ret[i] = opt1;
			used[ret[i]] = 1;
			continue;
		}

		int updown = query(i, i + 2);
		if(max(ret[i + 2], max(ret[i + 1], opt1)) - min(ret[i + 2], min(ret[i + 1], opt1)) == updown){
			ret[i] = opt1;
		}
		else
			ret[i] = opt2;

		used[ret[i]] = 1;
	}

	for(int i = 1; i <= N; i++){
		answer(i, ret[i]);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 308 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 4 ms 428 KB Output is correct
5 Correct 3 ms 428 KB Output is correct
6 Correct 3 ms 484 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 4 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 4 ms 560 KB Output is correct
13 Correct 4 ms 560 KB Output is correct
14 Correct 4 ms 560 KB Output is correct
15 Correct 3 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 308 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 4 ms 428 KB Output is correct
5 Correct 3 ms 428 KB Output is correct
6 Correct 3 ms 484 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 4 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 4 ms 560 KB Output is correct
13 Correct 4 ms 560 KB Output is correct
14 Correct 4 ms 560 KB Output is correct
15 Correct 3 ms 564 KB Output is correct
16 Correct 5 ms 564 KB Output is correct
17 Correct 8 ms 564 KB Output is correct
18 Correct 6 ms 568 KB Output is correct
19 Correct 13 ms 568 KB Output is correct
20 Correct 17 ms 568 KB Output is correct
21 Correct 17 ms 572 KB Output is correct
22 Correct 16 ms 572 KB Output is correct
23 Correct 14 ms 572 KB Output is correct
24 Correct 15 ms 572 KB Output is correct
25 Correct 8 ms 572 KB Output is correct
26 Correct 14 ms 576 KB Output is correct
27 Correct 9 ms 576 KB Output is correct
28 Correct 15 ms 576 KB Output is correct
29 Correct 12 ms 576 KB Output is correct
30 Correct 13 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 308 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 4 ms 428 KB Output is correct
5 Correct 3 ms 428 KB Output is correct
6 Correct 3 ms 484 KB Output is correct
7 Correct 3 ms 560 KB Output is correct
8 Correct 4 ms 560 KB Output is correct
9 Correct 3 ms 560 KB Output is correct
10 Correct 3 ms 560 KB Output is correct
11 Correct 3 ms 560 KB Output is correct
12 Correct 4 ms 560 KB Output is correct
13 Correct 4 ms 560 KB Output is correct
14 Correct 4 ms 560 KB Output is correct
15 Correct 3 ms 564 KB Output is correct
16 Correct 5 ms 564 KB Output is correct
17 Correct 8 ms 564 KB Output is correct
18 Correct 6 ms 568 KB Output is correct
19 Correct 13 ms 568 KB Output is correct
20 Correct 17 ms 568 KB Output is correct
21 Correct 17 ms 572 KB Output is correct
22 Correct 16 ms 572 KB Output is correct
23 Correct 14 ms 572 KB Output is correct
24 Correct 15 ms 572 KB Output is correct
25 Correct 8 ms 572 KB Output is correct
26 Correct 14 ms 576 KB Output is correct
27 Correct 9 ms 576 KB Output is correct
28 Correct 15 ms 576 KB Output is correct
29 Correct 12 ms 576 KB Output is correct
30 Correct 13 ms 576 KB Output is correct
31 Correct 32 ms 576 KB Output is correct
32 Correct 35 ms 576 KB Output is correct
33 Correct 45 ms 700 KB Output is correct
34 Correct 64 ms 712 KB Output is correct
35 Correct 66 ms 712 KB Output is correct
36 Correct 58 ms 712 KB Output is correct
37 Correct 23 ms 712 KB Output is correct
38 Correct 37 ms 712 KB Output is correct
39 Correct 56 ms 712 KB Output is correct
40 Correct 73 ms 712 KB Output is correct
41 Correct 28 ms 712 KB Output is correct
42 Correct 63 ms 712 KB Output is correct
43 Correct 63 ms 712 KB Output is correct
44 Correct 46 ms 712 KB Output is correct
45 Correct 68 ms 712 KB Output is correct
46 Correct 78 ms 712 KB Output is correct
47 Correct 31 ms 712 KB Output is correct
48 Correct 31 ms 712 KB Output is correct
49 Correct 47 ms 712 KB Output is correct
50 Correct 61 ms 712 KB Output is correct
51 Correct 52 ms 712 KB Output is correct
52 Correct 45 ms 724 KB Output is correct
53 Correct 54 ms 724 KB Output is correct
54 Correct 61 ms 724 KB Output is correct
55 Correct 74 ms 724 KB Output is correct
56 Correct 69 ms 724 KB Output is correct
57 Correct 70 ms 724 KB Output is correct
58 Correct 30 ms 724 KB Output is correct
59 Correct 80 ms 724 KB Output is correct
60 Correct 81 ms 724 KB Output is correct