#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
static int A[5005];
bool vis[5005];
/*int query(int l, int r) {
cout << l << ' ' << r << endl;
int x; cin >> x;
return x;
}*/
void solve(int N) {
int l = 1, r = N;
while (r - l > 1) {
int mid = (l + r) / 2;
if (query(mid, N) == N - 1)
l = mid;
else
r = mid;
}
A[l] = 1;
vis[1] = true;
if (l > 1) {
A[l - 1] = query(l - 1, l) + 1;
vis[A[l - 1]] = true;
}
A[l + 1] = query(l, l + 1) + 1;
vis[A[l + 1]] = true;
vis[0] = vis[N + 1] = true;
for (int i = l - 2; i > 0; i--) {
int d1 = query(i, i + 1);
if (!vis[max(0, A[i + 1] - d1)] && !vis[min(N + 1, A[i + 1] + d1)]) {
int d2 = query(i, i + 2);
if (d2 == max(max(A[i + 1], A[i + 2]), A[i + 1] + d1) - min(min(A[i + 1], A[i + 2]), A[i + 1] + d1))
A[i] = A[i + 1] + d1;
else
A[i] = A[i + 1] - d1;
/*if (d2 == abs(A[i + 1] - A[i + 2])) {
A[i] = A[i + 1] > A[i + 2] ? A[i + 1] - d1 : A[i + 1] + d1;
}
else {
A[i] = A[i + 1] > A[i + 2] ? A[i + 1] + d1 : A[i + 1] - d1;
}*/
}
else if (!vis[max(0, A[i + 1] - d1)])
A[i] = A[i + 1] - d1;
else
A[i] = A[i + 1] + d1;
vis[A[i]] = true;
}
for (int i = l + 2; i <= N; i++) {
int d1 = query(i - 1, i);
if (!vis[max(0, A[i - 1] - d1)] && !vis[min(N + 1, A[i - 1] + d1)]) {
int d2 = query(i - 2, i);
if (d2 == max(max(A[i - 1], A[i - 2]), A[i - 1] + d1) - min(min(A[i - 1], A[i - 2]), A[i - 1] + d1))
A[i] = A[i - 1] + d1;
else
A[i] = A[i - 1] - d1;
/*if (d2 == abs(A[i - 1] - A[i - 2])) {
A[i] = A[i - 1] > A[i - 2] ? A[i - 1] - d1 : A[i - 1] + d1;
}
else
A[i] = A[i - 1] > A[i - 2] ? A[i - 1] + d1 : A[i - 1] - d1;*/
}
else if (!vis[max(0, A[i - 1] - d1)])
A[i] = A[i - 1] - d1;
else
A[i] = A[i - 1] + d1;
vis[A[i]] = true;
}
for (int i = 1; i <= N; i++)
answer(i, A[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
440 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
432 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
440 KB |
Output is correct |
11 |
Correct |
1 ms |
440 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
1 ms |
440 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
440 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
432 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
440 KB |
Output is correct |
11 |
Correct |
1 ms |
440 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
1 ms |
440 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Correct |
2 ms |
440 KB |
Output is correct |
17 |
Correct |
3 ms |
448 KB |
Output is correct |
18 |
Correct |
6 ms |
700 KB |
Output is correct |
19 |
Correct |
5 ms |
696 KB |
Output is correct |
20 |
Correct |
6 ms |
696 KB |
Output is correct |
21 |
Correct |
5 ms |
436 KB |
Output is correct |
22 |
Correct |
5 ms |
692 KB |
Output is correct |
23 |
Correct |
5 ms |
688 KB |
Output is correct |
24 |
Correct |
5 ms |
696 KB |
Output is correct |
25 |
Correct |
4 ms |
444 KB |
Output is correct |
26 |
Correct |
6 ms |
692 KB |
Output is correct |
27 |
Correct |
6 ms |
696 KB |
Output is correct |
28 |
Correct |
5 ms |
696 KB |
Output is correct |
29 |
Correct |
5 ms |
948 KB |
Output is correct |
30 |
Correct |
5 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
440 KB |
Output is correct |
6 |
Correct |
1 ms |
440 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
432 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
440 KB |
Output is correct |
11 |
Correct |
1 ms |
440 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
1 ms |
440 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Correct |
2 ms |
440 KB |
Output is correct |
17 |
Correct |
3 ms |
448 KB |
Output is correct |
18 |
Correct |
6 ms |
700 KB |
Output is correct |
19 |
Correct |
5 ms |
696 KB |
Output is correct |
20 |
Correct |
6 ms |
696 KB |
Output is correct |
21 |
Correct |
5 ms |
436 KB |
Output is correct |
22 |
Correct |
5 ms |
692 KB |
Output is correct |
23 |
Correct |
5 ms |
688 KB |
Output is correct |
24 |
Correct |
5 ms |
696 KB |
Output is correct |
25 |
Correct |
4 ms |
444 KB |
Output is correct |
26 |
Correct |
6 ms |
692 KB |
Output is correct |
27 |
Correct |
6 ms |
696 KB |
Output is correct |
28 |
Correct |
5 ms |
696 KB |
Output is correct |
29 |
Correct |
5 ms |
948 KB |
Output is correct |
30 |
Correct |
5 ms |
1112 KB |
Output is correct |
31 |
Correct |
16 ms |
696 KB |
Output is correct |
32 |
Correct |
23 ms |
696 KB |
Output is correct |
33 |
Correct |
23 ms |
696 KB |
Output is correct |
34 |
Correct |
30 ms |
692 KB |
Output is correct |
35 |
Correct |
33 ms |
448 KB |
Output is correct |
36 |
Correct |
22 ms |
952 KB |
Output is correct |
37 |
Correct |
21 ms |
948 KB |
Output is correct |
38 |
Correct |
21 ms |
948 KB |
Output is correct |
39 |
Correct |
27 ms |
944 KB |
Output is correct |
40 |
Correct |
28 ms |
696 KB |
Output is correct |
41 |
Correct |
36 ms |
448 KB |
Output is correct |
42 |
Correct |
22 ms |
700 KB |
Output is correct |
43 |
Correct |
22 ms |
692 KB |
Output is correct |
44 |
Correct |
24 ms |
944 KB |
Output is correct |
45 |
Correct |
35 ms |
696 KB |
Output is correct |
46 |
Correct |
34 ms |
952 KB |
Output is correct |
47 |
Correct |
28 ms |
952 KB |
Output is correct |
48 |
Correct |
31 ms |
692 KB |
Output is correct |
49 |
Correct |
31 ms |
700 KB |
Output is correct |
50 |
Correct |
28 ms |
700 KB |
Output is correct |
51 |
Correct |
25 ms |
948 KB |
Output is correct |
52 |
Correct |
26 ms |
692 KB |
Output is correct |
53 |
Correct |
33 ms |
940 KB |
Output is correct |
54 |
Correct |
26 ms |
700 KB |
Output is correct |
55 |
Correct |
29 ms |
704 KB |
Output is correct |
56 |
Correct |
29 ms |
936 KB |
Output is correct |
57 |
Correct |
27 ms |
696 KB |
Output is correct |
58 |
Correct |
27 ms |
440 KB |
Output is correct |
59 |
Correct |
28 ms |
696 KB |
Output is correct |
60 |
Correct |
35 ms |
452 KB |
Output is correct |