#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
static int A[5000];
int sv[5010][5010],CC=0;
int myqry(int l,int r){
if(l>r)swap(l,r);
if(l==r)return 0;
if(sv[l][r])return sv[l][r];
assert(++CC<10000);
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:21:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | 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 |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
788 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 |
600 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 |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
788 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 |
600 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
6 ms |
2224 KB |
Output is correct |
18 |
Correct |
8 ms |
3672 KB |
Output is correct |
19 |
Correct |
10 ms |
4296 KB |
Output is correct |
20 |
Correct |
10 ms |
4440 KB |
Output is correct |
21 |
Correct |
9 ms |
4416 KB |
Output is correct |
22 |
Correct |
10 ms |
4440 KB |
Output is correct |
23 |
Correct |
15 ms |
4272 KB |
Output is correct |
24 |
Correct |
8 ms |
4444 KB |
Output is correct |
25 |
Correct |
12 ms |
4492 KB |
Output is correct |
26 |
Correct |
15 ms |
4556 KB |
Output is correct |
27 |
Correct |
10 ms |
4440 KB |
Output is correct |
28 |
Correct |
10 ms |
4440 KB |
Output is correct |
29 |
Correct |
10 ms |
4460 KB |
Output is correct |
30 |
Correct |
10 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 |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
788 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 |
600 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
6 ms |
2224 KB |
Output is correct |
18 |
Correct |
8 ms |
3672 KB |
Output is correct |
19 |
Correct |
10 ms |
4296 KB |
Output is correct |
20 |
Correct |
10 ms |
4440 KB |
Output is correct |
21 |
Correct |
9 ms |
4416 KB |
Output is correct |
22 |
Correct |
10 ms |
4440 KB |
Output is correct |
23 |
Correct |
15 ms |
4272 KB |
Output is correct |
24 |
Correct |
8 ms |
4444 KB |
Output is correct |
25 |
Correct |
12 ms |
4492 KB |
Output is correct |
26 |
Correct |
15 ms |
4556 KB |
Output is correct |
27 |
Correct |
10 ms |
4440 KB |
Output is correct |
28 |
Correct |
10 ms |
4440 KB |
Output is correct |
29 |
Correct |
10 ms |
4460 KB |
Output is correct |
30 |
Correct |
10 ms |
4444 KB |
Output is correct |
31 |
Correct |
21 ms |
9084 KB |
Output is correct |
32 |
Correct |
40 ms |
12936 KB |
Output is correct |
33 |
Correct |
51 ms |
17880 KB |
Output is correct |
34 |
Correct |
61 ms |
20820 KB |
Output is correct |
35 |
Correct |
54 ms |
20720 KB |
Output is correct |
36 |
Incorrect |
61 ms |
20484 KB |
Wrong Answer [2] |
37 |
Halted |
0 ms |
0 KB |
- |