#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
// static int a[5000];
int a[5004];
int mp[5004][5004];
void solve(int n) {
// int value = query(1, N);
// for(int i = 1; i <= N; i++) {
// answer(i, i);
// }
int dis = query(1,2);
// map<pair<int,int>,int> mp;
mp[1][2]=dis;
for(int i = 3; i <= n; i++){
mp[i-1][i] = query(i-1, i);
mp[i-2][i] = query(i-2, i);
}
for(int i = 1; i <= n; i++){
a[1] = i;
bool c = 1;
if(i + dis <= n){
c = 1;
a[2] = i + dis;
vector<int> used(n+1,0);
used[a[1]] = 1;
used[a[2]] = 2;
for(int j = 3; j <= n; j++){
int x = a[j-1] - mp[j-1][j];
if(x >= 1 && used[x] == 0){
if((max({x,a[j-1],a[j-2]})-min({x,a[j-1],a[j-2]})==mp[j-2][j]) && (max(x,a[j-1]) - min(x,a[j-1])==mp[j-1][j])){
a[j] = x;
used[x] = j;
continue;
}
}
x = a[j-1] + mp[j-1][j];
if(x <= n && used[x] == 0){
if((max({x,a[j-1],a[j-2]})-min({x,a[j-1],a[j-2]})==mp[j-2][j]) && (max(x,a[j-1]) - min(x,a[j-1])==mp[j-1][j])){
a[j] = x;
used[x] = j;
continue;
}
}
c = 0;
}
if(c&&used[1]<used[n]){
for(int j = 1;j<=n;j++){
// cout<<a[j]<<" ";
answer(j,a[j]);
}
// cout<<endl;
return;
}
}
if(i - dis >= 1){
c = 1;
a[2] = i - dis;
vector<int> used(n+1,0);
used[a[1]] = 1;
used[a[2]] = 2;
for(int j = 3;j<=n;j++){
int x = a[j-1] - mp[j-1][j];
if(x >= 1 && used[x] == 0){
if((max({x,a[j-1],a[j-2]})-min({x,a[j-1],a[j-2]})==mp[j-2][j]) && (max(x,a[j-1]) - min(x,a[j-1])==mp[j-1][j])){
a[j] = x;
used[x] = j;
continue;
}
}
x = a[j-1] + mp[j-1][j];
if(x <= n && used[x] == 0){
if((max({x,a[j-1],a[j-2]})-min({x,a[j-1],a[j-2]})==mp[j-2][j]) && (max(x,a[j-1]) - min(x,a[j-1])==mp[j-1][j])){
a[j] = x;
used[x] = j;
continue;
}
}
c = 0;
}
if(c&&used[1]<used[n]){
for(int j = 1;j<=n;j++){
// cout<<a[j]<<" ";
answer(j,a[j]);
}
// cout<<endl;
return;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
3 ms |
6488 KB |
Output is correct |
17 |
Correct |
8 ms |
10584 KB |
Output is correct |
18 |
Correct |
9 ms |
16728 KB |
Output is correct |
19 |
Correct |
19 ms |
20824 KB |
Output is correct |
20 |
Correct |
16 ms |
20976 KB |
Output is correct |
21 |
Correct |
13 ms |
20816 KB |
Output is correct |
22 |
Correct |
16 ms |
20984 KB |
Output is correct |
23 |
Correct |
16 ms |
21072 KB |
Output is correct |
24 |
Correct |
17 ms |
20824 KB |
Output is correct |
25 |
Correct |
9 ms |
21080 KB |
Output is correct |
26 |
Correct |
16 ms |
20996 KB |
Output is correct |
27 |
Correct |
11 ms |
21072 KB |
Output is correct |
28 |
Correct |
10 ms |
21080 KB |
Output is correct |
29 |
Correct |
16 ms |
20824 KB |
Output is correct |
30 |
Correct |
14 ms |
20816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2392 KB |
Output is correct |
8 |
Correct |
2 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 |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
3 ms |
6488 KB |
Output is correct |
17 |
Correct |
8 ms |
10584 KB |
Output is correct |
18 |
Correct |
9 ms |
16728 KB |
Output is correct |
19 |
Correct |
19 ms |
20824 KB |
Output is correct |
20 |
Correct |
16 ms |
20976 KB |
Output is correct |
21 |
Correct |
13 ms |
20816 KB |
Output is correct |
22 |
Correct |
16 ms |
20984 KB |
Output is correct |
23 |
Correct |
16 ms |
21072 KB |
Output is correct |
24 |
Correct |
17 ms |
20824 KB |
Output is correct |
25 |
Correct |
9 ms |
21080 KB |
Output is correct |
26 |
Correct |
16 ms |
20996 KB |
Output is correct |
27 |
Correct |
11 ms |
21072 KB |
Output is correct |
28 |
Correct |
10 ms |
21080 KB |
Output is correct |
29 |
Correct |
16 ms |
20824 KB |
Output is correct |
30 |
Correct |
14 ms |
20816 KB |
Output is correct |
31 |
Correct |
29 ms |
44276 KB |
Output is correct |
32 |
Correct |
75 ms |
61992 KB |
Output is correct |
33 |
Correct |
86 ms |
86564 KB |
Output is correct |
34 |
Correct |
128 ms |
97044 KB |
Output is correct |
35 |
Correct |
119 ms |
97576 KB |
Output is correct |
36 |
Correct |
66 ms |
97064 KB |
Output is correct |
37 |
Correct |
142 ms |
97104 KB |
Output is correct |
38 |
Correct |
58 ms |
97828 KB |
Output is correct |
39 |
Correct |
86 ms |
97056 KB |
Output is correct |
40 |
Correct |
105 ms |
97108 KB |
Output is correct |
41 |
Correct |
156 ms |
97208 KB |
Output is correct |
42 |
Correct |
65 ms |
97360 KB |
Output is correct |
43 |
Correct |
133 ms |
97248 KB |
Output is correct |
44 |
Correct |
58 ms |
97044 KB |
Output is correct |
45 |
Correct |
87 ms |
97456 KB |
Output is correct |
46 |
Correct |
246 ms |
97360 KB |
Output is correct |
47 |
Correct |
229 ms |
97616 KB |
Output is correct |
48 |
Correct |
49 ms |
97164 KB |
Output is correct |
49 |
Correct |
235 ms |
97040 KB |
Output is correct |
50 |
Correct |
231 ms |
97572 KB |
Output is correct |
51 |
Correct |
85 ms |
97376 KB |
Output is correct |
52 |
Correct |
71 ms |
97052 KB |
Output is correct |
53 |
Correct |
211 ms |
97020 KB |
Output is correct |
54 |
Correct |
144 ms |
97120 KB |
Output is correct |
55 |
Correct |
169 ms |
97116 KB |
Output is correct |
56 |
Correct |
93 ms |
97140 KB |
Output is correct |
57 |
Correct |
166 ms |
97208 KB |
Output is correct |
58 |
Correct |
100 ms |
97144 KB |
Output is correct |
59 |
Correct |
125 ms |
97404 KB |
Output is correct |
60 |
Correct |
94 ms |
97212 KB |
Output is correct |