#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int a[5100];
int n;
int bs(){
int l=1,r=n,ret;
while(l<=r){
int mid=(l+r)/2;
if(query(mid,n)==n-1){
ret=mid;
l=mid+1;
}
else r=mid-1;
}
return ret;
}
bool vis[5100];
bool av(int x){
if(x>=1&&x<=n)return 1-vis[x];
return 0;
}
void solve(int N) {
n=N;
int on=bs();
//cout<<on<<endl;
a[on]=1;
vis[1]=1;
a[on+1]=1+query(on,on+1);
vis[a[on+1]]=1;
for(int i=on;i+2<=n;i++){
int d12=query(i+1,i+2);
int d01=a[i+1]-a[i];
d01=max(d01,-d01);
if(!av(a[i+1]+d12)||!av(a[i+1]-d12)){
if(!av(a[i+1]+d12)){
a[i+2]=a[i+1]-d12;
vis[a[i+2]]=1;
}
else{
a[i+2]=a[i+1]+d12;
vis[a[i+2]]=1;
}
continue;
}
int d03=query(i,i+2);
if(d03==d01+d12){
if(a[i+1]>a[i])a[i+2]=a[i+1]+d12;
else a[i+2]=a[i+1]-d12;
vis[a[i+2]]=1;
}
else{
if(a[i+1]>a[i])a[i+2]=a[i+1]-d12;
else a[i+2]=a[i+1]+d12;
vis[a[i+2]]=1;
}
}
if(on-1>=1){
a[on-1]=a[on]+query(on-1,on);
vis[a[on-1]]=1;
}
for(int i=on;i-2>=1;i--){
int d21=query(i-2,i-1);
if(!av(a[i-1]+d21)||!av(a[i-1]-d21)){
if(!av(a[i-1]+d21)){
a[i-2]=a[i-1]-d21;
}
else{
a[i-2]=a[i-1]+d21;
}
vis[a[i-2]]=1;
continue;
}
int d10=a[i-1]-a[i];
d10=max(d10,-d10);
int d20=query(i-2,i);
if(d20==d21+d10){
if(a[i-1]>a[i])a[i-2]=a[i-1]+d21;
else a[i-2]=a[i-1]-d21;
}
else{
if(a[i-1]>a[i])a[i-2]=a[i-1]-d21;
else a[i-2]=a[i-1]+d21;
}
vis[a[i-2]]=1;
}
for(int i=1;i<=n;i++){
answer(i,a[i]);
}
}
Compilation message
xylophone.cpp: In function 'int bs()':
xylophone.cpp:17:12: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
17 | return ret;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
288 KB |
Output is correct |
16 |
Correct |
3 ms |
416 KB |
Output is correct |
17 |
Correct |
6 ms |
256 KB |
Output is correct |
18 |
Correct |
12 ms |
256 KB |
Output is correct |
19 |
Correct |
11 ms |
384 KB |
Output is correct |
20 |
Correct |
12 ms |
376 KB |
Output is correct |
21 |
Correct |
11 ms |
384 KB |
Output is correct |
22 |
Correct |
11 ms |
384 KB |
Output is correct |
23 |
Correct |
9 ms |
384 KB |
Output is correct |
24 |
Correct |
10 ms |
384 KB |
Output is correct |
25 |
Correct |
12 ms |
384 KB |
Output is correct |
26 |
Correct |
8 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
384 KB |
Output is correct |
28 |
Correct |
14 ms |
384 KB |
Output is correct |
29 |
Correct |
11 ms |
256 KB |
Output is correct |
30 |
Correct |
14 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
288 KB |
Output is correct |
16 |
Correct |
3 ms |
416 KB |
Output is correct |
17 |
Correct |
6 ms |
256 KB |
Output is correct |
18 |
Correct |
12 ms |
256 KB |
Output is correct |
19 |
Correct |
11 ms |
384 KB |
Output is correct |
20 |
Correct |
12 ms |
376 KB |
Output is correct |
21 |
Correct |
11 ms |
384 KB |
Output is correct |
22 |
Correct |
11 ms |
384 KB |
Output is correct |
23 |
Correct |
9 ms |
384 KB |
Output is correct |
24 |
Correct |
10 ms |
384 KB |
Output is correct |
25 |
Correct |
12 ms |
384 KB |
Output is correct |
26 |
Correct |
8 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
384 KB |
Output is correct |
28 |
Correct |
14 ms |
384 KB |
Output is correct |
29 |
Correct |
11 ms |
256 KB |
Output is correct |
30 |
Correct |
14 ms |
384 KB |
Output is correct |
31 |
Correct |
31 ms |
384 KB |
Output is correct |
32 |
Correct |
36 ms |
384 KB |
Output is correct |
33 |
Correct |
31 ms |
376 KB |
Output is correct |
34 |
Correct |
54 ms |
384 KB |
Output is correct |
35 |
Correct |
61 ms |
384 KB |
Output is correct |
36 |
Correct |
47 ms |
376 KB |
Output is correct |
37 |
Correct |
36 ms |
436 KB |
Output is correct |
38 |
Correct |
48 ms |
384 KB |
Output is correct |
39 |
Correct |
35 ms |
512 KB |
Output is correct |
40 |
Correct |
57 ms |
384 KB |
Output is correct |
41 |
Correct |
56 ms |
384 KB |
Output is correct |
42 |
Correct |
51 ms |
376 KB |
Output is correct |
43 |
Correct |
42 ms |
384 KB |
Output is correct |
44 |
Correct |
46 ms |
376 KB |
Output is correct |
45 |
Correct |
51 ms |
384 KB |
Output is correct |
46 |
Correct |
61 ms |
376 KB |
Output is correct |
47 |
Correct |
57 ms |
504 KB |
Output is correct |
48 |
Correct |
70 ms |
520 KB |
Output is correct |
49 |
Correct |
64 ms |
384 KB |
Output is correct |
50 |
Correct |
47 ms |
520 KB |
Output is correct |
51 |
Correct |
61 ms |
388 KB |
Output is correct |
52 |
Correct |
52 ms |
384 KB |
Output is correct |
53 |
Correct |
57 ms |
384 KB |
Output is correct |
54 |
Correct |
59 ms |
504 KB |
Output is correct |
55 |
Correct |
67 ms |
504 KB |
Output is correct |
56 |
Correct |
71 ms |
392 KB |
Output is correct |
57 |
Correct |
65 ms |
388 KB |
Output is correct |
58 |
Correct |
66 ms |
384 KB |
Output is correct |
59 |
Correct |
60 ms |
516 KB |
Output is correct |
60 |
Correct |
41 ms |
376 KB |
Output is correct |