#include "xylophone.h"
static int A[5010];
static bool used[5010]={0};
int n;
inline void Set(int i, int x) {
A[i]=x;
used[x]=1;
}
inline bool Poss(int x) {
return 1<=x&&x<=n&&!used[x];
}
void solve(int N) {
n=N;
int lo=1, hi=N, x, y;
while(lo<hi) {
int mid=(lo+hi+1)/2;
x=query(mid,N);
if(x==N-1) lo=mid;
else hi=mid-1;
}
Set(lo,1);
int i;
if(lo+1<=N) {
x=query(lo,lo+1);
Set(lo+1,x+1);
}
if(lo-1>=1) {
x=query(lo-1,lo);
Set(lo-1,x+1);
}
for(i=lo+2;i<=N;i++) {
x=query(i-1,i);
if(!Poss(A[i-1]+x)) {
Set(i,A[i-1]-x);
} else if(!Poss(A[i-1]-x)) {
Set(i,A[i-1]+x);
} else {
if(A[i-2]>A[i-1]) {
y=query(i-2,i);
if(y==A[i-2]-A[i-1]+x) {
Set(i,A[i-1]-x);
} else {
Set(i,A[i-1]+x);
}
} else {
y=query(i-2,i);
if(y==A[i-1]-A[i-2]+x) {
Set(i,A[i-1]+x);
} else {
Set(i,A[i-1]-x);
}
}
}
}
for(i=lo-2;i>=1;i--) {
x=query(i,i+1);
if(!Poss(A[i+1]+x)) {
Set(i,A[i+1]-x);
} else if(!Poss(A[i+1]-x)) {
Set(i,A[i+1]+x);
} else {
if(A[i+2]>A[i+1]) {
y=query(i,i+2);
if(y==A[i+2]-A[i+1]+x) {
Set(i,A[i+1]-x);
} else {
Set(i,A[i+1]+x);
}
} else {
y=query(i,i+2);
if(y==A[i+1]-A[i+2]+x) {
Set(i,A[i+1]+x);
} else {
Set(i,A[i+1]-x);
}
}
}
}
for(i=1;i<=N;i++) answer(i,A[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
252 KB |
Output is correct |
7 |
Correct |
4 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
300 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
296 KB |
Output is correct |
12 |
Correct |
3 ms |
248 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
252 KB |
Output is correct |
7 |
Correct |
4 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
300 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
296 KB |
Output is correct |
12 |
Correct |
3 ms |
248 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
10 ms |
248 KB |
Output is correct |
18 |
Correct |
15 ms |
376 KB |
Output is correct |
19 |
Correct |
16 ms |
388 KB |
Output is correct |
20 |
Correct |
12 ms |
392 KB |
Output is correct |
21 |
Correct |
17 ms |
248 KB |
Output is correct |
22 |
Correct |
15 ms |
248 KB |
Output is correct |
23 |
Correct |
13 ms |
376 KB |
Output is correct |
24 |
Correct |
8 ms |
388 KB |
Output is correct |
25 |
Correct |
16 ms |
296 KB |
Output is correct |
26 |
Correct |
15 ms |
424 KB |
Output is correct |
27 |
Correct |
15 ms |
380 KB |
Output is correct |
28 |
Correct |
14 ms |
248 KB |
Output is correct |
29 |
Correct |
11 ms |
392 KB |
Output is correct |
30 |
Correct |
16 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
252 KB |
Output is correct |
7 |
Correct |
4 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
300 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
296 KB |
Output is correct |
12 |
Correct |
3 ms |
248 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
10 ms |
248 KB |
Output is correct |
18 |
Correct |
15 ms |
376 KB |
Output is correct |
19 |
Correct |
16 ms |
388 KB |
Output is correct |
20 |
Correct |
12 ms |
392 KB |
Output is correct |
21 |
Correct |
17 ms |
248 KB |
Output is correct |
22 |
Correct |
15 ms |
248 KB |
Output is correct |
23 |
Correct |
13 ms |
376 KB |
Output is correct |
24 |
Correct |
8 ms |
388 KB |
Output is correct |
25 |
Correct |
16 ms |
296 KB |
Output is correct |
26 |
Correct |
15 ms |
424 KB |
Output is correct |
27 |
Correct |
15 ms |
380 KB |
Output is correct |
28 |
Correct |
14 ms |
248 KB |
Output is correct |
29 |
Correct |
11 ms |
392 KB |
Output is correct |
30 |
Correct |
16 ms |
248 KB |
Output is correct |
31 |
Correct |
36 ms |
252 KB |
Output is correct |
32 |
Correct |
46 ms |
376 KB |
Output is correct |
33 |
Correct |
60 ms |
248 KB |
Output is correct |
34 |
Correct |
43 ms |
312 KB |
Output is correct |
35 |
Correct |
50 ms |
316 KB |
Output is correct |
36 |
Correct |
30 ms |
388 KB |
Output is correct |
37 |
Correct |
57 ms |
316 KB |
Output is correct |
38 |
Correct |
57 ms |
376 KB |
Output is correct |
39 |
Correct |
66 ms |
452 KB |
Output is correct |
40 |
Correct |
63 ms |
404 KB |
Output is correct |
41 |
Correct |
37 ms |
512 KB |
Output is correct |
42 |
Correct |
50 ms |
376 KB |
Output is correct |
43 |
Correct |
59 ms |
424 KB |
Output is correct |
44 |
Correct |
43 ms |
320 KB |
Output is correct |
45 |
Correct |
77 ms |
248 KB |
Output is correct |
46 |
Correct |
69 ms |
440 KB |
Output is correct |
47 |
Correct |
67 ms |
248 KB |
Output is correct |
48 |
Correct |
54 ms |
424 KB |
Output is correct |
49 |
Correct |
40 ms |
304 KB |
Output is correct |
50 |
Correct |
55 ms |
320 KB |
Output is correct |
51 |
Correct |
76 ms |
248 KB |
Output is correct |
52 |
Correct |
45 ms |
424 KB |
Output is correct |
53 |
Correct |
69 ms |
384 KB |
Output is correct |
54 |
Correct |
48 ms |
400 KB |
Output is correct |
55 |
Correct |
48 ms |
408 KB |
Output is correct |
56 |
Correct |
77 ms |
316 KB |
Output is correct |
57 |
Correct |
88 ms |
320 KB |
Output is correct |
58 |
Correct |
38 ms |
388 KB |
Output is correct |
59 |
Correct |
97 ms |
504 KB |
Output is correct |
60 |
Correct |
82 ms |
376 KB |
Output is correct |