#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
int a[5005],d[5005][5005];
void solve(int n){
int _=query(1,2);
for(int i=3; i<=n; i++) d[i-2][i]=query(i-2,i);
for(int i=2; i<=n; i++) d[i-1][i]=query(i-1,i);
for(int i=1; i<=n; i++){
a[1]=i;
for(int __=-1; __<=1; __+=2){
vector <int> vis(n+1,0);
vis[a[1]]++;
a[2]=a[1]+__*_;
if(a[2]>=1 and a[2]<=n) vis[a[2]]++;
int cnt=0;
for(int j=3; j<=n; j++){
int v=d[j-2][j];
int l=d[j-1][j];
if(v==max(a[j-1],a[j-2])-min(a[j-1],a[j-2])){
if(a[j-1]>a[j-2]) a[j]=a[j-1]-l;
else a[j]=a[j-1]+l;
}else{
int ifmin=a[j-1]-l;
int ifmax=a[j-1]+l;
if(ifmin>0 and max({a[j-2],a[j-1]})-ifmin==v) a[j]=ifmin;
else a[j]=ifmax;
}
if(a[j]>=1 and a[j]<=n) vis[a[j]]++;
}
int fir=1,last=0;
for(int j=1; j<=n; j++) if(a[j]==1) fir=j;
for(int j=1; j<=n; j++) if(a[j]==n) last=j;
if(fir>last) continue;
bool ck=1;
for(int i=1; i<=n; i++) if(vis[i]!=1) ck=0;
if(!ck) continue;
for(int i=1; i<=n; i++) answer(i,a[i]);
return;
}
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:18:8: warning: unused variable 'cnt' [-Wunused-variable]
18 | int cnt=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
6488 KB |
Output is correct |
17 |
Correct |
7 ms |
10584 KB |
Output is correct |
18 |
Correct |
12 ms |
17132 KB |
Output is correct |
19 |
Correct |
17 ms |
21076 KB |
Output is correct |
20 |
Correct |
19 ms |
20824 KB |
Output is correct |
21 |
Correct |
22 ms |
21004 KB |
Output is correct |
22 |
Correct |
22 ms |
20824 KB |
Output is correct |
23 |
Correct |
11 ms |
21000 KB |
Output is correct |
24 |
Correct |
18 ms |
20824 KB |
Output is correct |
25 |
Correct |
11 ms |
20996 KB |
Output is correct |
26 |
Correct |
18 ms |
21080 KB |
Output is correct |
27 |
Correct |
17 ms |
21004 KB |
Output is correct |
28 |
Correct |
13 ms |
20824 KB |
Output is correct |
29 |
Correct |
15 ms |
20824 KB |
Output is correct |
30 |
Correct |
16 ms |
21228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2388 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
2 ms |
6488 KB |
Output is correct |
17 |
Correct |
7 ms |
10584 KB |
Output is correct |
18 |
Correct |
12 ms |
17132 KB |
Output is correct |
19 |
Correct |
17 ms |
21076 KB |
Output is correct |
20 |
Correct |
19 ms |
20824 KB |
Output is correct |
21 |
Correct |
22 ms |
21004 KB |
Output is correct |
22 |
Correct |
22 ms |
20824 KB |
Output is correct |
23 |
Correct |
11 ms |
21000 KB |
Output is correct |
24 |
Correct |
18 ms |
20824 KB |
Output is correct |
25 |
Correct |
11 ms |
20996 KB |
Output is correct |
26 |
Correct |
18 ms |
21080 KB |
Output is correct |
27 |
Correct |
17 ms |
21004 KB |
Output is correct |
28 |
Correct |
13 ms |
20824 KB |
Output is correct |
29 |
Correct |
15 ms |
20824 KB |
Output is correct |
30 |
Correct |
16 ms |
21228 KB |
Output is correct |
31 |
Correct |
38 ms |
43600 KB |
Output is correct |
32 |
Correct |
133 ms |
62032 KB |
Output is correct |
33 |
Correct |
137 ms |
86800 KB |
Output is correct |
34 |
Correct |
237 ms |
97112 KB |
Output is correct |
35 |
Correct |
264 ms |
97376 KB |
Output is correct |
36 |
Correct |
78 ms |
97360 KB |
Output is correct |
37 |
Correct |
174 ms |
97168 KB |
Output is correct |
38 |
Correct |
56 ms |
97368 KB |
Output is correct |
39 |
Correct |
104 ms |
97360 KB |
Output is correct |
40 |
Correct |
180 ms |
97100 KB |
Output is correct |
41 |
Correct |
280 ms |
97360 KB |
Output is correct |
42 |
Correct |
70 ms |
97168 KB |
Output is correct |
43 |
Correct |
169 ms |
97364 KB |
Output is correct |
44 |
Correct |
62 ms |
97052 KB |
Output is correct |
45 |
Correct |
152 ms |
97360 KB |
Output is correct |
46 |
Correct |
282 ms |
97044 KB |
Output is correct |
47 |
Correct |
277 ms |
97492 KB |
Output is correct |
48 |
Correct |
72 ms |
97400 KB |
Output is correct |
49 |
Correct |
285 ms |
97404 KB |
Output is correct |
50 |
Correct |
281 ms |
97356 KB |
Output is correct |
51 |
Correct |
149 ms |
97348 KB |
Output is correct |
52 |
Correct |
108 ms |
97360 KB |
Output is correct |
53 |
Correct |
310 ms |
97144 KB |
Output is correct |
54 |
Correct |
270 ms |
97208 KB |
Output is correct |
55 |
Correct |
317 ms |
97212 KB |
Output is correct |
56 |
Correct |
336 ms |
97164 KB |
Output is correct |
57 |
Correct |
280 ms |
97356 KB |
Output is correct |
58 |
Correct |
407 ms |
97212 KB |
Output is correct |
59 |
Correct |
222 ms |
97360 KB |
Output is correct |
60 |
Correct |
188 ms |
97336 KB |
Output is correct |