#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
const int mxn=5001;
int a[mxn];
int ek;
int cnt[mxn]={};
void solve(int N)
{
int k;
int lo=1;
int hi=N;
while(lo<=hi)
{
int mid=lo+hi>>1;
if(query(mid,N)==N-1)
{
lo=mid+1;
}
else
{
k=mid;
hi=mid-1;
}
}
a[k-1]=1;
cnt[1]=1;
ek=k-1;
for(int i=ek-1;i>0;i--)
{
k=query(i,i+1);
if(a[i+1]-k<=0 || cnt[a[i+1]-k]==1)
{
a[i]=a[i+1]+k;
cnt[a[i+1]+k]=1;
}
else if(a[i+1]+k>N || cnt[a[i+1]+k]==1)
{
a[i]=a[i+1]-k;
cnt[a[i+1]-k]=1;
}
else
{
int tmp=query(i,i+2);
if(max(a[i+1]+k,a[i+2])-min(a[i+1],a[i+2])==tmp)
{
a[i]=a[i+1]+k;
cnt[a[i+1]+k]=1;
}
else
{
a[i]=a[i+1]-k;
cnt[a[i+1]-k]=1;
}
}
}
for(int i=ek+1;i<=N;i++)
{
k=query(i-1,i);
if(a[i-1]-k<=0 || cnt[a[i-1]-k]==1)
{
a[i]=a[i-1]+k;
cnt[a[i-1]+k]=1;
}
else if(a[i-1]+k>N || cnt[a[i-1]+k]==1)
{
a[i]=a[i-1]-k;
cnt[a[i-1]-k]=1;
}
else
{
int tmp=query(i-2,i);
if(max(a[i-1]+k,a[i-2])-min(a[i-1],a[i-2])==tmp)
{
a[i]=a[i-1]+k;
cnt[a[i-1]+k]=1;
}
else
{
a[i]=a[i-1]-k;
cnt[a[i-1]-k]=1;
}
}
}
for(int i = 1; i <= N; i++)
{
answer(i,a[i]);
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:16:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=lo+hi>>1;
~~^~~
xylophone.cpp:36:10: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
for(int i=ek-1;i>0;i--)
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
316 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
3 ms |
396 KB |
Output is correct |
7 |
Correct |
3 ms |
248 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
248 KB |
Output is correct |
13 |
Correct |
3 ms |
380 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
316 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
3 ms |
396 KB |
Output is correct |
7 |
Correct |
3 ms |
248 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
248 KB |
Output is correct |
13 |
Correct |
3 ms |
380 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
400 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
9 ms |
376 KB |
Output is correct |
18 |
Correct |
12 ms |
248 KB |
Output is correct |
19 |
Correct |
12 ms |
376 KB |
Output is correct |
20 |
Correct |
10 ms |
316 KB |
Output is correct |
21 |
Correct |
9 ms |
404 KB |
Output is correct |
22 |
Correct |
9 ms |
396 KB |
Output is correct |
23 |
Correct |
12 ms |
248 KB |
Output is correct |
24 |
Correct |
12 ms |
248 KB |
Output is correct |
25 |
Correct |
12 ms |
376 KB |
Output is correct |
26 |
Correct |
15 ms |
376 KB |
Output is correct |
27 |
Correct |
16 ms |
248 KB |
Output is correct |
28 |
Correct |
19 ms |
248 KB |
Output is correct |
29 |
Correct |
16 ms |
248 KB |
Output is correct |
30 |
Correct |
14 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
316 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
3 ms |
396 KB |
Output is correct |
7 |
Correct |
3 ms |
248 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
248 KB |
Output is correct |
13 |
Correct |
3 ms |
380 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
400 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
9 ms |
376 KB |
Output is correct |
18 |
Correct |
12 ms |
248 KB |
Output is correct |
19 |
Correct |
12 ms |
376 KB |
Output is correct |
20 |
Correct |
10 ms |
316 KB |
Output is correct |
21 |
Correct |
9 ms |
404 KB |
Output is correct |
22 |
Correct |
9 ms |
396 KB |
Output is correct |
23 |
Correct |
12 ms |
248 KB |
Output is correct |
24 |
Correct |
12 ms |
248 KB |
Output is correct |
25 |
Correct |
12 ms |
376 KB |
Output is correct |
26 |
Correct |
15 ms |
376 KB |
Output is correct |
27 |
Correct |
16 ms |
248 KB |
Output is correct |
28 |
Correct |
19 ms |
248 KB |
Output is correct |
29 |
Correct |
16 ms |
248 KB |
Output is correct |
30 |
Correct |
14 ms |
316 KB |
Output is correct |
31 |
Correct |
36 ms |
376 KB |
Output is correct |
32 |
Correct |
46 ms |
348 KB |
Output is correct |
33 |
Correct |
37 ms |
432 KB |
Output is correct |
34 |
Correct |
68 ms |
348 KB |
Output is correct |
35 |
Correct |
63 ms |
476 KB |
Output is correct |
36 |
Correct |
47 ms |
348 KB |
Output is correct |
37 |
Correct |
61 ms |
252 KB |
Output is correct |
38 |
Correct |
51 ms |
376 KB |
Output is correct |
39 |
Correct |
73 ms |
248 KB |
Output is correct |
40 |
Correct |
51 ms |
340 KB |
Output is correct |
41 |
Correct |
73 ms |
248 KB |
Output is correct |
42 |
Correct |
59 ms |
380 KB |
Output is correct |
43 |
Correct |
51 ms |
376 KB |
Output is correct |
44 |
Correct |
62 ms |
248 KB |
Output is correct |
45 |
Correct |
48 ms |
324 KB |
Output is correct |
46 |
Correct |
81 ms |
380 KB |
Output is correct |
47 |
Correct |
65 ms |
436 KB |
Output is correct |
48 |
Correct |
78 ms |
248 KB |
Output is correct |
49 |
Correct |
55 ms |
400 KB |
Output is correct |
50 |
Correct |
37 ms |
400 KB |
Output is correct |
51 |
Correct |
67 ms |
352 KB |
Output is correct |
52 |
Correct |
43 ms |
524 KB |
Output is correct |
53 |
Correct |
65 ms |
376 KB |
Output is correct |
54 |
Correct |
70 ms |
248 KB |
Output is correct |
55 |
Correct |
62 ms |
376 KB |
Output is correct |
56 |
Correct |
54 ms |
376 KB |
Output is correct |
57 |
Correct |
64 ms |
352 KB |
Output is correct |
58 |
Correct |
73 ms |
384 KB |
Output is correct |
59 |
Correct |
69 ms |
248 KB |
Output is correct |
60 |
Correct |
68 ms |
248 KB |
Output is correct |