#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n) {
int l = 1, r = n, ind = 0, md;
while ( l <= r ) {
md = (l + r) / 2;
if ( query( md, n ) == n - 1 ) {
l = md + 1;
ind = md;
}
else {
r = md - 1;
}
}
vector < int > a( n + 1 ), used(n + 1);
a[ind] = 1;
answer( ind, 1 );
used[1] = 1;
if ( ind + 1 <= n ) {
int x = query( ind, ind + 1 );
a[ind + 1] = x + 1;
answer( ind + 1, x + 1 );
used[x + 1] = 1;
}
if ( ind - 1 > 0 ) {
int x = query( ind - 1, ind );
a[ind - 1] = x + 1;
answer( ind - 1, x + 1 );
used[x + 1] = 1;
}
for ( int i = ind + 2; i <= n; i++ ) {
int x = a[ i - 1 ], y = a[i - 2];
int d = query( i - 1, i );
if ( x - d < 1 || used[x - d] ) {
a[i] = x + d;
answer( i, x + d );
used[x + d] = 1;
continue;
}
if ( x + d > n || used[x + d] ) {
a[i] = x - d;
answer( i, x - d );
used[x - d] = 1;
continue;
}
int q = query( i - 2, i );
int mx = max( { x, y, x - d } ), mn = min( { x, y, x - d } );
if ( q == mx - mn ) {
a[i] = x - d;
answer( i, x - d );
used[x - d] = 1;
}
else {
a[i] = x + d;
answer( i, x + d );
used[x + d] = 1;
}
}
for ( int i = ind - 2; i > 0; i-- ) {
int x = a[ i + 1 ], y = a[i + 2];
int d = query( i, i + 1 );
if ( x - d < 1 || used[x - d] ) {
a[i] = x + d;
answer( i, x + d );
used[x + d] = 1;
continue;
}
if ( x + d > n ) {
a[i] = x - d;
answer( i, x - d );
used[x - d] = 1;
continue;
}
int q = query( i, i + 2 );
int mx = max( { x, y, x - d } ), mn = min( { x, y, x - d } );
if ( q == mx - mn ) {
a[i] = x - d;
answer( i, x - d );
used[x - d] = 1;
}
else {
a[i] = x + d;
answer( i, x + d );
used[x + d] = 1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
256 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
6 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
256 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
6 ms |
256 KB |
Output is correct |
16 |
Correct |
8 ms |
384 KB |
Output is correct |
17 |
Correct |
17 ms |
256 KB |
Output is correct |
18 |
Correct |
13 ms |
256 KB |
Output is correct |
19 |
Correct |
20 ms |
256 KB |
Output is correct |
20 |
Correct |
22 ms |
384 KB |
Output is correct |
21 |
Correct |
26 ms |
256 KB |
Output is correct |
22 |
Correct |
19 ms |
256 KB |
Output is correct |
23 |
Correct |
12 ms |
256 KB |
Output is correct |
24 |
Correct |
18 ms |
256 KB |
Output is correct |
25 |
Correct |
13 ms |
256 KB |
Output is correct |
26 |
Correct |
22 ms |
384 KB |
Output is correct |
27 |
Correct |
22 ms |
256 KB |
Output is correct |
28 |
Correct |
18 ms |
256 KB |
Output is correct |
29 |
Correct |
24 ms |
384 KB |
Output is correct |
30 |
Correct |
19 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
256 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
256 KB |
Output is correct |
14 |
Correct |
6 ms |
256 KB |
Output is correct |
15 |
Correct |
6 ms |
256 KB |
Output is correct |
16 |
Correct |
8 ms |
384 KB |
Output is correct |
17 |
Correct |
17 ms |
256 KB |
Output is correct |
18 |
Correct |
13 ms |
256 KB |
Output is correct |
19 |
Correct |
20 ms |
256 KB |
Output is correct |
20 |
Correct |
22 ms |
384 KB |
Output is correct |
21 |
Correct |
26 ms |
256 KB |
Output is correct |
22 |
Correct |
19 ms |
256 KB |
Output is correct |
23 |
Correct |
12 ms |
256 KB |
Output is correct |
24 |
Correct |
18 ms |
256 KB |
Output is correct |
25 |
Correct |
13 ms |
256 KB |
Output is correct |
26 |
Correct |
22 ms |
384 KB |
Output is correct |
27 |
Correct |
22 ms |
256 KB |
Output is correct |
28 |
Correct |
18 ms |
256 KB |
Output is correct |
29 |
Correct |
24 ms |
384 KB |
Output is correct |
30 |
Correct |
19 ms |
256 KB |
Output is correct |
31 |
Correct |
33 ms |
384 KB |
Output is correct |
32 |
Correct |
48 ms |
384 KB |
Output is correct |
33 |
Correct |
69 ms |
384 KB |
Output is correct |
34 |
Correct |
55 ms |
384 KB |
Output is correct |
35 |
Correct |
61 ms |
384 KB |
Output is correct |
36 |
Correct |
47 ms |
384 KB |
Output is correct |
37 |
Correct |
59 ms |
384 KB |
Output is correct |
38 |
Correct |
50 ms |
384 KB |
Output is correct |
39 |
Correct |
60 ms |
384 KB |
Output is correct |
40 |
Correct |
75 ms |
384 KB |
Output is correct |
41 |
Correct |
61 ms |
384 KB |
Output is correct |
42 |
Correct |
53 ms |
384 KB |
Output is correct |
43 |
Correct |
67 ms |
384 KB |
Output is correct |
44 |
Correct |
61 ms |
384 KB |
Output is correct |
45 |
Correct |
66 ms |
384 KB |
Output is correct |
46 |
Correct |
70 ms |
384 KB |
Output is correct |
47 |
Correct |
71 ms |
384 KB |
Output is correct |
48 |
Correct |
63 ms |
384 KB |
Output is correct |
49 |
Correct |
89 ms |
384 KB |
Output is correct |
50 |
Correct |
75 ms |
384 KB |
Output is correct |
51 |
Correct |
59 ms |
384 KB |
Output is correct |
52 |
Correct |
63 ms |
384 KB |
Output is correct |
53 |
Correct |
63 ms |
384 KB |
Output is correct |
54 |
Correct |
60 ms |
416 KB |
Output is correct |
55 |
Correct |
59 ms |
384 KB |
Output is correct |
56 |
Correct |
67 ms |
384 KB |
Output is correct |
57 |
Correct |
58 ms |
384 KB |
Output is correct |
58 |
Correct |
70 ms |
384 KB |
Output is correct |
59 |
Correct |
61 ms |
384 KB |
Output is correct |
60 |
Correct |
85 ms |
384 KB |
Output is correct |