Submission #63495

# Submission time Handle Problem Language Result Execution time Memory
63495 2018-08-02T02:39:43 Z win11905 Xylophone (JOI18_xylophone) C++11
100 / 100
172 ms 832 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

int n, A[5005];

int getl() {
	int l = 1, r = n;
	while(l < r) {
		int m = l + r + 1>> 1;
		if(query(m, n) == n-1) l = m;
		r = m-1; 
	}
	return l;
}

int getNum(int a1, int a2, int a, int b) {
	if(a > b) {
		if(a2 - a1 == a - b) return a + a1;
		return a - a1;
	} else {
		if(a2 - a1 == b - a) return a - a1;
		return a + a1;
	}
}

void solve(int N) {
	n = N;
	A[1] = 0, A[2] = query(1, 2);
	for(int i = 3; i <= n; ++i) A[i] = getNum(query(i-1, i), query(i-2, i), A[i-1], A[i-2]);
	int mn = *min_element(A+1, A+n+1);
	int p1, pn;
	for_each(A+1, A+n+1, [&](int &x) { x = x - mn + 1; });
	for(int i = 1; i <= n; ++i) {
		if(A[i] == 1) p1 = i;
		if(A[i] == n) pn = i;
	}
	if(p1 > pn) for_each(A+1, A+n+1, [&](int &x) { x = n - x + 1; });
	for(int i = 1; i <= n; ++i) answer(i, A[i]);
}

Compilation message

xylophone.cpp: In function 'int getl()':
xylophone.cpp:10:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r + 1>> 1;
           ~~~~~~^~~
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:38:2: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if(p1 > pn) for_each(A+1, A+n+1, [&](int &x) { x = n - x + 1; });
  ^~
xylophone.cpp:38:2: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 9 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 9 ms 520 KB Output is correct
16 Correct 13 ms 536 KB Output is correct
17 Correct 7 ms 536 KB Output is correct
18 Correct 16 ms 536 KB Output is correct
19 Correct 22 ms 536 KB Output is correct
20 Correct 15 ms 536 KB Output is correct
21 Correct 42 ms 536 KB Output is correct
22 Correct 21 ms 536 KB Output is correct
23 Correct 17 ms 568 KB Output is correct
24 Correct 44 ms 568 KB Output is correct
25 Correct 15 ms 692 KB Output is correct
26 Correct 31 ms 692 KB Output is correct
27 Correct 20 ms 692 KB Output is correct
28 Correct 47 ms 692 KB Output is correct
29 Correct 25 ms 700 KB Output is correct
30 Correct 36 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 9 ms 520 KB Output is correct
16 Correct 13 ms 536 KB Output is correct
17 Correct 7 ms 536 KB Output is correct
18 Correct 16 ms 536 KB Output is correct
19 Correct 22 ms 536 KB Output is correct
20 Correct 15 ms 536 KB Output is correct
21 Correct 42 ms 536 KB Output is correct
22 Correct 21 ms 536 KB Output is correct
23 Correct 17 ms 568 KB Output is correct
24 Correct 44 ms 568 KB Output is correct
25 Correct 15 ms 692 KB Output is correct
26 Correct 31 ms 692 KB Output is correct
27 Correct 20 ms 692 KB Output is correct
28 Correct 47 ms 692 KB Output is correct
29 Correct 25 ms 700 KB Output is correct
30 Correct 36 ms 700 KB Output is correct
31 Correct 75 ms 700 KB Output is correct
32 Correct 59 ms 700 KB Output is correct
33 Correct 56 ms 700 KB Output is correct
34 Correct 129 ms 700 KB Output is correct
35 Correct 129 ms 700 KB Output is correct
36 Correct 63 ms 700 KB Output is correct
37 Correct 151 ms 700 KB Output is correct
38 Correct 158 ms 704 KB Output is correct
39 Correct 151 ms 824 KB Output is correct
40 Correct 139 ms 824 KB Output is correct
41 Correct 151 ms 824 KB Output is correct
42 Correct 99 ms 832 KB Output is correct
43 Correct 137 ms 832 KB Output is correct
44 Correct 163 ms 832 KB Output is correct
45 Correct 66 ms 832 KB Output is correct
46 Correct 81 ms 832 KB Output is correct
47 Correct 90 ms 832 KB Output is correct
48 Correct 107 ms 832 KB Output is correct
49 Correct 64 ms 832 KB Output is correct
50 Correct 147 ms 832 KB Output is correct
51 Correct 172 ms 832 KB Output is correct
52 Correct 125 ms 832 KB Output is correct
53 Correct 77 ms 832 KB Output is correct
54 Correct 140 ms 832 KB Output is correct
55 Correct 108 ms 832 KB Output is correct
56 Correct 113 ms 832 KB Output is correct
57 Correct 110 ms 832 KB Output is correct
58 Correct 103 ms 832 KB Output is correct
59 Correct 96 ms 832 KB Output is correct
60 Correct 95 ms 832 KB Output is correct