답안 #63074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63074 2018-07-31T16:14:39 Z shoemakerjo Xylophone (JOI18_xylophone) C++14
100 / 100
85 ms 724 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#define maxn 5010

bool taken[maxn];
int ans[maxn];

void solve(int N) {

	//call query on range s to t
	//call answer setting index i to a
	fill(taken, taken+maxn, false);

	int small = 1;
	for (int inc = (1 << 14); inc > 0; inc /= 2) {
		if (small + inc > N) continue;
		int nx = small + inc;
		int qu = query(nx, N);
		if (qu == N-1) {
			//did not go too far
			small = nx;
		}
	}
	// cout << "small: " << small << endl;
	ans[small] = 1;
	taken[1] = true;
	if (small != 1) {
		ans[small-1] = query(small-1, small)+1;
		taken[ans[small-1]] = true;
	}
	if (small != N) {
		ans[small+1] = query(small, small+1)+1;
		taken[ans[small-1]] = true;
	}
	for (int i = small-2; i >= 1; i--) {
		int nx = i+1;
		int nx2 = i+2;
		int q1 = query(i, nx); //reverse inputs for other direction

		int op1 = ans[nx] + q1; //is greater
		int op2 = ans[nx] - q1; //is less 
		if (taken[op1] || op1 < 1 || op1 > N) {
			ans[i] = op2;
			taken[op2] = true;
			continue;
		}
		if (taken[op2] || op2 < 1 || op2 > N) {
			ans[i] = op1;
			taken[op1] = true;
			continue;
		}

		int q2 = query(i, nx2);
		if (q2 == abs(ans[nx]-ans[nx2])) {
			//nothing changed (i am between them)
			if (ans[nx2] > ans[nx]) {
				ans[i] = op1;
				taken[op1] = true;
				continue;
			}
			else {
				ans[i] = op2;
				taken[op2] = true;
				continue;
			}
		}
		else {
			int mx = 0;
			mx = max(mx, abs(ans[nx2]-ans[nx]));
			mx = max(mx, abs(ans[nx]-op1));
			mx = max(mx, abs(ans[nx2]-op1));
			//something happened
			if (mx == q2) {
				ans[i] = op1;
				taken[op1] = true;

			}
			else {
				ans[i] = op2;
				taken[op2] = true;
			}
		}


	}
	for (int i = small+2; i <= N; i++) {
		int nx = i-1;
		int nx2 = i-2;

		int q1 = query(nx, i); //reverse inputs for other direction

		int op1 = ans[nx] + q1; //is greater
		int op2 = ans[nx] - q1; //is less 
		if (taken[op1] || op1 < 1 || op1 > N) {
			ans[i] = op2;
			taken[op2] = true;
			continue;
		}
		if (taken[op2] || op2 < 1 || op2 > N) {
			ans[i] = op1;
			taken[op1] = true;
			continue;
		}

		int q2 = query(nx2, i);
		if (q2 == abs(ans[nx]-ans[nx2])) {
			//nothing changed (i am between them)
			if (ans[nx2] > ans[nx]) {
				ans[i] = op1;
				taken[op1] = true;
				continue;
			}
			else {
				ans[i] = op2;
				taken[op2] = true;
				continue;
			}
		}
		else {
			int mx = 0;
			mx = max(mx, abs(ans[nx2]-ans[nx]));
			mx = max(mx, abs(ans[nx]-op1));
			mx = max(mx, abs(ans[nx2]-op1));
			//something happened
			if (mx == q2) {
				ans[i] = op1;
				taken[op1] = true;

			}
			else {
				ans[i] = op2;
				taken[op2] = true;
			}
		}

	}

	for (int i = 1; i <= N; i++) {
		// cout << "answering: " << i << ":    " << ans[i] << endl;
		answer(i, ans[i]);
	}



}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 4 ms 440 KB Output is correct
5 Correct 3 ms 448 KB Output is correct
6 Correct 5 ms 464 KB Output is correct
7 Correct 5 ms 464 KB Output is correct
8 Correct 4 ms 464 KB Output is correct
9 Correct 4 ms 464 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 4 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 4 ms 440 KB Output is correct
5 Correct 3 ms 448 KB Output is correct
6 Correct 5 ms 464 KB Output is correct
7 Correct 5 ms 464 KB Output is correct
8 Correct 4 ms 464 KB Output is correct
9 Correct 4 ms 464 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 4 ms 544 KB Output is correct
16 Correct 3 ms 548 KB Output is correct
17 Correct 8 ms 548 KB Output is correct
18 Correct 13 ms 548 KB Output is correct
19 Correct 16 ms 572 KB Output is correct
20 Correct 19 ms 572 KB Output is correct
21 Correct 17 ms 700 KB Output is correct
22 Correct 18 ms 700 KB Output is correct
23 Correct 9 ms 700 KB Output is correct
24 Correct 11 ms 700 KB Output is correct
25 Correct 16 ms 704 KB Output is correct
26 Correct 12 ms 704 KB Output is correct
27 Correct 9 ms 704 KB Output is correct
28 Correct 8 ms 704 KB Output is correct
29 Correct 14 ms 704 KB Output is correct
30 Correct 14 ms 704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 3 ms 440 KB Output is correct
4 Correct 4 ms 440 KB Output is correct
5 Correct 3 ms 448 KB Output is correct
6 Correct 5 ms 464 KB Output is correct
7 Correct 5 ms 464 KB Output is correct
8 Correct 4 ms 464 KB Output is correct
9 Correct 4 ms 464 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 4 ms 544 KB Output is correct
16 Correct 3 ms 548 KB Output is correct
17 Correct 8 ms 548 KB Output is correct
18 Correct 13 ms 548 KB Output is correct
19 Correct 16 ms 572 KB Output is correct
20 Correct 19 ms 572 KB Output is correct
21 Correct 17 ms 700 KB Output is correct
22 Correct 18 ms 700 KB Output is correct
23 Correct 9 ms 700 KB Output is correct
24 Correct 11 ms 700 KB Output is correct
25 Correct 16 ms 704 KB Output is correct
26 Correct 12 ms 704 KB Output is correct
27 Correct 9 ms 704 KB Output is correct
28 Correct 8 ms 704 KB Output is correct
29 Correct 14 ms 704 KB Output is correct
30 Correct 14 ms 704 KB Output is correct
31 Correct 28 ms 704 KB Output is correct
32 Correct 36 ms 704 KB Output is correct
33 Correct 30 ms 704 KB Output is correct
34 Correct 53 ms 704 KB Output is correct
35 Correct 62 ms 704 KB Output is correct
36 Correct 49 ms 712 KB Output is correct
37 Correct 41 ms 712 KB Output is correct
38 Correct 44 ms 712 KB Output is correct
39 Correct 75 ms 712 KB Output is correct
40 Correct 71 ms 712 KB Output is correct
41 Correct 81 ms 712 KB Output is correct
42 Correct 34 ms 712 KB Output is correct
43 Correct 53 ms 712 KB Output is correct
44 Correct 28 ms 712 KB Output is correct
45 Correct 85 ms 712 KB Output is correct
46 Correct 80 ms 712 KB Output is correct
47 Correct 33 ms 712 KB Output is correct
48 Correct 85 ms 712 KB Output is correct
49 Correct 71 ms 712 KB Output is correct
50 Correct 31 ms 712 KB Output is correct
51 Correct 49 ms 712 KB Output is correct
52 Correct 60 ms 712 KB Output is correct
53 Correct 49 ms 712 KB Output is correct
54 Correct 55 ms 712 KB Output is correct
55 Correct 64 ms 712 KB Output is correct
56 Correct 52 ms 712 KB Output is correct
57 Correct 27 ms 712 KB Output is correct
58 Correct 46 ms 712 KB Output is correct
59 Correct 46 ms 724 KB Output is correct
60 Correct 75 ms 724 KB Output is correct