#include "xylophone.h"
#include<iostream>
int ans[5005+5],val1[5005+4],val2[5005+4],mx,id1,id2,value[5005+4];
static int A[5000];
void solve(int N) {
/*l=2; r=N;
while(l<=r){
int mid=(l+r)/2;
if(query(mid,N)!=N-1){
ind=mid-1; r=mid-1;
}
else l=mid+1;
}
ans[ind]=1;
if(ind!=n) ans[ind+1]=query(ind,ind+1)+1;
if(ind!=1) ans[ind-1]=query(ind,ind-1)+1;
*/
value[3]=query(1,2);
ans[1]=0; ans[2]=value[3]; mx=value[3]; id1=1;id2=2;
int mn=0;
for(int k=3;k<=N;k++){
val1[k]=query(k-2,k);
val2[k]=query(k-1,k);
if(ans[k-1]<ans[k-2]){
if(val1[k]==value[k]) ans[k]=ans[k-1]+val2[k];
else if(val1[k]==val2[k]) ans[k]=ans[k-1]+val2[k];
else ans[k]=ans[k-1]-val2[k];
}
else {
if(value[k]==val1[k] || val1[k]==val2[k]) ans[k]=ans[k-1]-val2[k];
else ans[k]=ans[k-1]+val2[k];
}
value[k+1]=val2[k];
if(ans[k]<mn)mn=ans[k],id1=k;
if(ans[k]>mx)mx=ans[k],id2=k;
}
if(id1>id2){
mn=0; std::swap(ans[1],ans[2]);
for(int k=3;k<=N;k++){
if(ans[k-1]<ans[k-2]){
if(val1[k]==value[k]) ans[k]=ans[k-1]+val2[k];
else if(val1[k]==val2[k]) ans[k]=ans[k-1]+val2[k];
else ans[k]=ans[k-1]-val2[k];
}
else {
if(value[k]==val1[k] || val1[k]==val2[k]) ans[k]=ans[k-1]-val2[k];
else ans[k]=ans[k-1]+val2[k];
}
value[k+1]=val2[k];
if(ans[k]<mn)mn=ans[k];
}
}
for(int k=1;k<=N;k++){
ans[k]+=1-mn;
answer(k,ans[k]);
}
}
Compilation message
xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
5 | static int A[5000];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
384 KB |
Output is correct |
18 |
Correct |
16 ms |
384 KB |
Output is correct |
19 |
Correct |
18 ms |
384 KB |
Output is correct |
20 |
Correct |
23 ms |
384 KB |
Output is correct |
21 |
Correct |
15 ms |
384 KB |
Output is correct |
22 |
Correct |
17 ms |
384 KB |
Output is correct |
23 |
Correct |
19 ms |
384 KB |
Output is correct |
24 |
Correct |
22 ms |
384 KB |
Output is correct |
25 |
Correct |
16 ms |
384 KB |
Output is correct |
26 |
Correct |
20 ms |
452 KB |
Output is correct |
27 |
Correct |
19 ms |
512 KB |
Output is correct |
28 |
Correct |
20 ms |
384 KB |
Output is correct |
29 |
Correct |
23 ms |
384 KB |
Output is correct |
30 |
Correct |
22 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
384 KB |
Output is correct |
18 |
Correct |
16 ms |
384 KB |
Output is correct |
19 |
Correct |
18 ms |
384 KB |
Output is correct |
20 |
Correct |
23 ms |
384 KB |
Output is correct |
21 |
Correct |
15 ms |
384 KB |
Output is correct |
22 |
Correct |
17 ms |
384 KB |
Output is correct |
23 |
Correct |
19 ms |
384 KB |
Output is correct |
24 |
Correct |
22 ms |
384 KB |
Output is correct |
25 |
Correct |
16 ms |
384 KB |
Output is correct |
26 |
Correct |
20 ms |
452 KB |
Output is correct |
27 |
Correct |
19 ms |
512 KB |
Output is correct |
28 |
Correct |
20 ms |
384 KB |
Output is correct |
29 |
Correct |
23 ms |
384 KB |
Output is correct |
30 |
Correct |
22 ms |
384 KB |
Output is correct |
31 |
Correct |
44 ms |
532 KB |
Output is correct |
32 |
Correct |
52 ms |
384 KB |
Output is correct |
33 |
Correct |
80 ms |
396 KB |
Output is correct |
34 |
Correct |
122 ms |
384 KB |
Output is correct |
35 |
Correct |
115 ms |
520 KB |
Output is correct |
36 |
Correct |
50 ms |
384 KB |
Output is correct |
37 |
Correct |
101 ms |
384 KB |
Output is correct |
38 |
Correct |
93 ms |
384 KB |
Output is correct |
39 |
Correct |
122 ms |
444 KB |
Output is correct |
40 |
Correct |
125 ms |
384 KB |
Output is correct |
41 |
Correct |
118 ms |
440 KB |
Output is correct |
42 |
Correct |
70 ms |
384 KB |
Output is correct |
43 |
Correct |
145 ms |
384 KB |
Output is correct |
44 |
Correct |
107 ms |
384 KB |
Output is correct |
45 |
Correct |
91 ms |
512 KB |
Output is correct |
46 |
Correct |
112 ms |
384 KB |
Output is correct |
47 |
Correct |
94 ms |
384 KB |
Output is correct |
48 |
Correct |
89 ms |
384 KB |
Output is correct |
49 |
Correct |
97 ms |
408 KB |
Output is correct |
50 |
Correct |
86 ms |
572 KB |
Output is correct |
51 |
Correct |
117 ms |
384 KB |
Output is correct |
52 |
Correct |
82 ms |
384 KB |
Output is correct |
53 |
Correct |
82 ms |
384 KB |
Output is correct |
54 |
Correct |
61 ms |
516 KB |
Output is correct |
55 |
Correct |
104 ms |
384 KB |
Output is correct |
56 |
Correct |
91 ms |
384 KB |
Output is correct |
57 |
Correct |
130 ms |
524 KB |
Output is correct |
58 |
Correct |
131 ms |
372 KB |
Output is correct |
59 |
Correct |
88 ms |
384 KB |
Output is correct |
60 |
Correct |
120 ms |
384 KB |
Output is correct |