Submission #642599

# Submission time Handle Problem Language Result Execution time Memory
642599 2022-09-20T08:06:08 Z TypeYippie Xylophone (JOI18_xylophone) C++14
100 / 100
99 ms 432 KB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

int ans1[5005], ans2[5005];

void solve(int n){
	// query(l, r); -> hit block l to r and determine the difference between maximum and minimum value within those range
	// answer(i, x); -> the value of Ai is x

	int b1 = 1, b2 = -1;
	ans1[1] = ans2[1] = 1;
	int prevDiff, diff, diff2;
	diff = query(1, 2);
	ans1[2] = ans1[1]+diff*b1;
	ans2[2] = ans2[1]+diff*b2;
	prevDiff = diff;
	int lowest1 = min(ans1[1], ans1[2]), lowest2 = min(ans2[1], ans2[2]);
	for(int i = 3; i <= n; i++){
		diff = query(i-1, i);
		diff2 = query(i-2, i);
		if(diff2 != diff+prevDiff){
			b1 *= -1;
			b2 *= -1;
		}
		ans1[i] = ans1[i-1]+diff*b1;
		ans2[i] = ans2[i-1]+diff*b2;
		lowest1 = min(lowest1, ans1[i]);
		lowest2 = min(lowest2, ans2[i]);
		prevDiff = diff;
	}	

	bool pass1 = false, pass2 = false, flag1 = true, flag2 = true;
	for(int i = 1; i <= n; i++){
		ans1[i] += lowest1*-1+1;
		ans2[i] += lowest2*-1+1;
		if(ans1[i] == 1){
			pass1 = true;
		}
		if(ans2[i] == 1){
			pass2 = true;
		}
		if((ans1[i] == n && !pass1) || ans1[i] > n){
			flag1 = false;
		}
		if((ans2[i] == n && !pass2) || ans2[i] > n){
			flag2 = false;
		}
	}

	if(flag1){
		for(int i = 1; i <= n; i++){
			answer(i, ans1[i]);
		}
	} else {
		printf("\n");
		for(int i = 1; i <= n; i++){
			answer(i, ans2[i]);
		}
	}

}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:34:51: warning: variable 'flag2' set but not used [-Wunused-but-set-variable]
   34 |  bool pass1 = false, pass2 = false, flag1 = true, flag2 = true;
      |                                                   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 8 ms 208 KB Output is correct
18 Correct 10 ms 304 KB Output is correct
19 Correct 27 ms 300 KB Output is correct
20 Correct 18 ms 208 KB Output is correct
21 Correct 14 ms 208 KB Output is correct
22 Correct 14 ms 208 KB Output is correct
23 Correct 19 ms 288 KB Output is correct
24 Correct 8 ms 304 KB Output is correct
25 Correct 16 ms 288 KB Output is correct
26 Correct 15 ms 312 KB Output is correct
27 Correct 18 ms 208 KB Output is correct
28 Correct 15 ms 292 KB Output is correct
29 Correct 21 ms 208 KB Output is correct
30 Correct 19 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 8 ms 208 KB Output is correct
18 Correct 10 ms 304 KB Output is correct
19 Correct 27 ms 300 KB Output is correct
20 Correct 18 ms 208 KB Output is correct
21 Correct 14 ms 208 KB Output is correct
22 Correct 14 ms 208 KB Output is correct
23 Correct 19 ms 288 KB Output is correct
24 Correct 8 ms 304 KB Output is correct
25 Correct 16 ms 288 KB Output is correct
26 Correct 15 ms 312 KB Output is correct
27 Correct 18 ms 208 KB Output is correct
28 Correct 15 ms 292 KB Output is correct
29 Correct 21 ms 208 KB Output is correct
30 Correct 19 ms 208 KB Output is correct
31 Correct 39 ms 292 KB Output is correct
32 Correct 62 ms 300 KB Output is correct
33 Correct 67 ms 424 KB Output is correct
34 Correct 69 ms 320 KB Output is correct
35 Correct 90 ms 300 KB Output is correct
36 Correct 72 ms 432 KB Output is correct
37 Correct 49 ms 328 KB Output is correct
38 Correct 64 ms 296 KB Output is correct
39 Correct 77 ms 320 KB Output is correct
40 Correct 87 ms 312 KB Output is correct
41 Correct 57 ms 300 KB Output is correct
42 Correct 81 ms 316 KB Output is correct
43 Correct 78 ms 312 KB Output is correct
44 Correct 67 ms 316 KB Output is correct
45 Correct 77 ms 292 KB Output is correct
46 Correct 80 ms 300 KB Output is correct
47 Correct 95 ms 300 KB Output is correct
48 Correct 76 ms 428 KB Output is correct
49 Correct 99 ms 320 KB Output is correct
50 Correct 83 ms 432 KB Output is correct
51 Correct 59 ms 296 KB Output is correct
52 Correct 88 ms 424 KB Output is correct
53 Correct 85 ms 300 KB Output is correct
54 Correct 56 ms 308 KB Output is correct
55 Correct 95 ms 320 KB Output is correct
56 Correct 73 ms 304 KB Output is correct
57 Correct 68 ms 300 KB Output is correct
58 Correct 93 ms 420 KB Output is correct
59 Correct 85 ms 308 KB Output is correct
60 Correct 76 ms 304 KB Output is correct