#include "xylophone.h"
#include "bits/stdc++.h"
static int A[5001];
void solve(int N){
int l = 1, r = N;
bool use[N + 1];
for(int i = 1; i <= N; i++)
use[i] = 0;
while(r - l > 1){
int mid = (l + r) / 2;
if(query(1, mid) == N - 1)
r = mid;
else
l = mid;
}
A[r] = N;
use[N] = 1;
int x = query(r - 1, r);
A[r - 1] = N - x;
use[N - x] = 1;
if(r != N){
x = query(r, r + 1);
A[r + 1] = N - x;
use[N - x] = 1;
}
for(int i = r - 2; i >= 1; i--){
x = query(i, i + 1);
if(A[i + 1] - x <= 0){
A[i] = A[i + 1] + x;
use[A[i + 1] + x] = 1;
continue;
}
if(A[i + 1] + x > N){
A[i] = A[i + 1] - x;
use[A[i + 1] - x] = 1;
continue;
}
if(use[A[i + 1] + x]){
A[i] = A[i + 1] - x;
use[A[i + 1] - x] = 1;
continue;
}
if(use[A[i + 1] - x]){
A[i] = A[i + 1] + x;
use[A[i + 1] + x] = 1;
continue;
}
int z = query(i, i + 2), y = abs(A[i + 1] - A[i + 2]);
if(!(z == x + y)){
if(A[i + 2] > A[i + 1]){
A[i] = A[i + 1] + x;
use[A[i + 1] + x] = 1;
}
else{
A[i] = A[i + 1] - x;
use[A[i + 1] - x] = 1;
}
}
else{
if(A[i + 2] > A[i + 1]){
A[i] = A[i + 1] - x;
use[A[i + 1] - x] = 1;
}
else{
A[i] = A[i + 1] + x;
use[A[i + 1] + x] = 1;
}
}
}
for(int i = r + 2; i <= N; i++){
x = query(i - 1, i);
if(A[i - 1] - x <= 0){
A[i] = A[i - 1] + x;
use[A[i - 1] + x] = 1;
continue;
}
if(A[i - 1] + x > N){
A[i] = A[i - 1] - x;
use[A[i - 1] - x] = 1;
continue;
}
if(use[A[i - 1] - x]){
A[i] = A[i - 1] + x;
use[A[i - 1] + x] = 1;
continue;
}
if(use[A[i - 1] - x]){
A[i] = A[i - 1] + x;
use[A[i - 1] + x] = 1;
continue;
}
int z = query(i - 2, i), y = abs(A[i - 1] - A[i - 2]);
if(!(z == x + y)){
if(A[i - 2] > A[i - 1]){
A[i] = A[i - 1] + x;
use[A[i - 1] + x] = 1;
}
else{
A[i] = A[i - 1] - x;
use[A[i - 1] - x] = 1;
}
}
else{
if(A[i - 2] > A[i - 1]){
A[i] = A[i - 1] - x;
use[A[i - 1] - x] = 1;
}
else{
A[i] = A[i - 1] + x;
use[A[i - 1] + x] = 1;
}
}
}
for(int i = 1; i <= N; i++)
answer(i, A[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
288 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 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 |
1 ms |
292 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
288 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 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 |
1 ms |
292 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
1 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 |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
208 KB |
Output is correct |
18 |
Correct |
9 ms |
208 KB |
Output is correct |
19 |
Correct |
8 ms |
208 KB |
Output is correct |
20 |
Correct |
6 ms |
308 KB |
Output is correct |
21 |
Correct |
13 ms |
208 KB |
Output is correct |
22 |
Correct |
13 ms |
208 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
10 ms |
336 KB |
Output is correct |
25 |
Correct |
10 ms |
300 KB |
Output is correct |
26 |
Correct |
11 ms |
308 KB |
Output is correct |
27 |
Correct |
10 ms |
208 KB |
Output is correct |
28 |
Correct |
15 ms |
208 KB |
Output is correct |
29 |
Correct |
10 ms |
208 KB |
Output is correct |
30 |
Correct |
14 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
288 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 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 |
1 ms |
292 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
1 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 |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
7 ms |
208 KB |
Output is correct |
18 |
Correct |
9 ms |
208 KB |
Output is correct |
19 |
Correct |
8 ms |
208 KB |
Output is correct |
20 |
Correct |
6 ms |
308 KB |
Output is correct |
21 |
Correct |
13 ms |
208 KB |
Output is correct |
22 |
Correct |
13 ms |
208 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
10 ms |
336 KB |
Output is correct |
25 |
Correct |
10 ms |
300 KB |
Output is correct |
26 |
Correct |
11 ms |
308 KB |
Output is correct |
27 |
Correct |
10 ms |
208 KB |
Output is correct |
28 |
Correct |
15 ms |
208 KB |
Output is correct |
29 |
Correct |
10 ms |
208 KB |
Output is correct |
30 |
Correct |
14 ms |
308 KB |
Output is correct |
31 |
Correct |
33 ms |
304 KB |
Output is correct |
32 |
Correct |
42 ms |
292 KB |
Output is correct |
33 |
Correct |
67 ms |
304 KB |
Output is correct |
34 |
Correct |
51 ms |
300 KB |
Output is correct |
35 |
Correct |
43 ms |
304 KB |
Output is correct |
36 |
Correct |
45 ms |
300 KB |
Output is correct |
37 |
Correct |
48 ms |
296 KB |
Output is correct |
38 |
Correct |
56 ms |
308 KB |
Output is correct |
39 |
Correct |
67 ms |
308 KB |
Output is correct |
40 |
Correct |
59 ms |
296 KB |
Output is correct |
41 |
Correct |
47 ms |
348 KB |
Output is correct |
42 |
Correct |
42 ms |
312 KB |
Output is correct |
43 |
Correct |
35 ms |
308 KB |
Output is correct |
44 |
Correct |
41 ms |
456 KB |
Output is correct |
45 |
Correct |
35 ms |
304 KB |
Output is correct |
46 |
Correct |
63 ms |
424 KB |
Output is correct |
47 |
Correct |
77 ms |
296 KB |
Output is correct |
48 |
Correct |
66 ms |
300 KB |
Output is correct |
49 |
Correct |
66 ms |
304 KB |
Output is correct |
50 |
Correct |
61 ms |
304 KB |
Output is correct |
51 |
Correct |
24 ms |
312 KB |
Output is correct |
52 |
Correct |
60 ms |
316 KB |
Output is correct |
53 |
Correct |
70 ms |
420 KB |
Output is correct |
54 |
Correct |
59 ms |
300 KB |
Output is correct |
55 |
Correct |
57 ms |
288 KB |
Output is correct |
56 |
Correct |
57 ms |
312 KB |
Output is correct |
57 |
Correct |
41 ms |
312 KB |
Output is correct |
58 |
Correct |
49 ms |
308 KB |
Output is correct |
59 |
Correct |
56 ms |
300 KB |
Output is correct |
60 |
Correct |
60 ms |
304 KB |
Output is correct |