#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
static int A[5000];
int sv[5010][5010];
int myqry(int l,int r){
if(l==r)return 0;
if(sv[l][r])return sv[l][r];
return sv[l][r]=query(l,r);
}
int ans[5010];
int makesense(int a,int b,int c,int ac){
return ac==max({a,b,c})-min({a,b,c});
}
void solve(int N) {
int l=1,r=N-1,res=0;
while(l<=r){
int mid=l+r>>1;
if(myqry(mid,N)==N-1)
res=mid,l=mid+1;
else r=mid-1;
}
int posof1=res;
ans[posof1]=1;
if(posof1>1)
ans[posof1-1]=myqry(posof1-1,posof1)+1;
ans[posof1+1]=myqry(posof1,posof1+1)+1;
for(int i=posof1-2;i>0;i--){
int k=myqry(i,i+1);
if(ans[i+1]-k<1)
ans[i]=ans[i+1]+k;
else if(ans[i+1]+k>N)
ans[i]=ans[i+1]-k;
else {
int c=query(i,i+2);
if(makesense(ans[i+1]-k,ans[i+1],ans[i+2],c))
ans[i]=ans[i+1]-k;
else ans[i]=ans[i+1]+k;
}
}
for(int i=posof1+2;i<=N;i++){
int k=myqry(i-1,i);
if(ans[i-1]-k<1)
ans[i]=ans[i-1]+k;
else if(ans[i+1]+k>N)
ans[i]=ans[i-1]-k;
else {
int c=query(i-2,i);
if(makesense(ans[i-1]-k,ans[i-1],ans[i-2],c))
ans[i]=ans[i-1]-k;
else ans[i]=ans[i-1]+k;
}
}
for(int i=1;i<=N;i++)
answer(i,ans[i]);
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:19:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | int mid=l+r>>1;
| ~^~
xylophone.cpp: At global scope:
xylophone.cpp:4:12: warning: 'A' defined but not used [-Wunused-variable]
4 | static int A[5000];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
712 KB |
Output is correct |
16 |
Correct |
3 ms |
1112 KB |
Output is correct |
17 |
Correct |
5 ms |
2404 KB |
Output is correct |
18 |
Correct |
7 ms |
3672 KB |
Output is correct |
19 |
Correct |
11 ms |
4460 KB |
Output is correct |
20 |
Correct |
8 ms |
4444 KB |
Output is correct |
21 |
Correct |
8 ms |
4376 KB |
Output is correct |
22 |
Correct |
9 ms |
4392 KB |
Output is correct |
23 |
Correct |
10 ms |
4424 KB |
Output is correct |
24 |
Correct |
10 ms |
4460 KB |
Output is correct |
25 |
Correct |
9 ms |
4444 KB |
Output is correct |
26 |
Correct |
10 ms |
4440 KB |
Output is correct |
27 |
Correct |
10 ms |
4336 KB |
Output is correct |
28 |
Correct |
10 ms |
4452 KB |
Output is correct |
29 |
Correct |
9 ms |
4284 KB |
Output is correct |
30 |
Correct |
8 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
712 KB |
Output is correct |
16 |
Correct |
3 ms |
1112 KB |
Output is correct |
17 |
Correct |
5 ms |
2404 KB |
Output is correct |
18 |
Correct |
7 ms |
3672 KB |
Output is correct |
19 |
Correct |
11 ms |
4460 KB |
Output is correct |
20 |
Correct |
8 ms |
4444 KB |
Output is correct |
21 |
Correct |
8 ms |
4376 KB |
Output is correct |
22 |
Correct |
9 ms |
4392 KB |
Output is correct |
23 |
Correct |
10 ms |
4424 KB |
Output is correct |
24 |
Correct |
10 ms |
4460 KB |
Output is correct |
25 |
Correct |
9 ms |
4444 KB |
Output is correct |
26 |
Correct |
10 ms |
4440 KB |
Output is correct |
27 |
Correct |
10 ms |
4336 KB |
Output is correct |
28 |
Correct |
10 ms |
4452 KB |
Output is correct |
29 |
Correct |
9 ms |
4284 KB |
Output is correct |
30 |
Correct |
8 ms |
4444 KB |
Output is correct |
31 |
Correct |
19 ms |
9200 KB |
Output is correct |
32 |
Correct |
26 ms |
12884 KB |
Output is correct |
33 |
Correct |
46 ms |
18268 KB |
Output is correct |
34 |
Correct |
39 ms |
20564 KB |
Output is correct |
35 |
Correct |
42 ms |
20908 KB |
Output is correct |
36 |
Incorrect |
61 ms |
20716 KB |
Wrong Answer [2] |
37 |
Halted |
0 ms |
0 KB |
- |