#include "xylophone.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
//~ static int A[5000];
void solve(int n){
vector<int> dd(n + 1);
for(int i=2;i<=n;i++){
dd[i] = query(i-1, i);
}
vector<int> t(n + 1);
for(int i=3;i<=n;i++){
t[i] = query(i-2, i);
}
vector<int> d(n + 1);
auto go = [&](){
for(int i=3;i<=n;i++){
if(t[i] == dd[i-1]){
if(d[i-1] < 0) d[i] = dd[i];
else d[i] = -dd[i];
} else if(t[i] == dd[i]){
if(d[i-1] < 0) d[i] = dd[i];
else d[i] = -dd[i];
} else {
if(d[i-1] < 0) d[i] = -dd[i];
else d[i] = dd[i];
}
}
};
d[2] = dd[2], go();
auto get = [&](int s){
vector<int> a(n + 1);
a[1] = s;
for(int i=2;i<=n;i++){
a[i] = a[i-1] + d[i];
} return a;
};
for(int s=1;s<=n;s++){
vector<int> a = get(s), cnt(n + 1);
bool ok = 1;
for(int i=1;i<=n;i++){
if(a[i] < 1 || a[i] > n || cnt[a[i]]) { ok = 0; break; }
if(a[i] == n && !cnt[1]) { ok = 0; break; }
cnt[a[i]] = 1;
} if(!ok) continue;
//~ for(int i=1;i<=n;i++) cout<<a[i]<<" ";
//~ cout<<"\n";
for(int i=1;i<=n;i++){
answer(i, a[i]);
}
}
d[2] = -dd[2], go();
for(int s=1;s<=n;s++){
vector<int> a = get(s), cnt(n + 1);
bool ok = 1;
for(int i=1;i<=n;i++){
if(a[i] < 1 || a[i] > n || cnt[a[i]]) { ok = 0; break; }
if(a[i] == n && !cnt[1]) { ok = 0; break; }
cnt[a[i]] = 1;
} if(!ok) continue;
//~ for(int i=1;i<=n;i++) cout<<a[i]<<" ";
//~ cout<<"\n";
for(int i=1;i<=n;i++){
answer(i, a[i]);
}
}
//~ assert(0);
}
/*
5
2 1 5 3 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
3 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
268 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
3 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
268 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
16 |
Correct |
4 ms |
200 KB |
Output is correct |
17 |
Correct |
11 ms |
296 KB |
Output is correct |
18 |
Correct |
21 ms |
200 KB |
Output is correct |
19 |
Correct |
24 ms |
296 KB |
Output is correct |
20 |
Correct |
30 ms |
300 KB |
Output is correct |
21 |
Correct |
23 ms |
280 KB |
Output is correct |
22 |
Correct |
18 ms |
296 KB |
Output is correct |
23 |
Correct |
31 ms |
280 KB |
Output is correct |
24 |
Correct |
21 ms |
276 KB |
Output is correct |
25 |
Correct |
27 ms |
284 KB |
Output is correct |
26 |
Correct |
15 ms |
296 KB |
Output is correct |
27 |
Correct |
15 ms |
288 KB |
Output is correct |
28 |
Correct |
25 ms |
292 KB |
Output is correct |
29 |
Correct |
18 ms |
200 KB |
Output is correct |
30 |
Correct |
24 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
3 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
268 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
16 |
Correct |
4 ms |
200 KB |
Output is correct |
17 |
Correct |
11 ms |
296 KB |
Output is correct |
18 |
Correct |
21 ms |
200 KB |
Output is correct |
19 |
Correct |
24 ms |
296 KB |
Output is correct |
20 |
Correct |
30 ms |
300 KB |
Output is correct |
21 |
Correct |
23 ms |
280 KB |
Output is correct |
22 |
Correct |
18 ms |
296 KB |
Output is correct |
23 |
Correct |
31 ms |
280 KB |
Output is correct |
24 |
Correct |
21 ms |
276 KB |
Output is correct |
25 |
Correct |
27 ms |
284 KB |
Output is correct |
26 |
Correct |
15 ms |
296 KB |
Output is correct |
27 |
Correct |
15 ms |
288 KB |
Output is correct |
28 |
Correct |
25 ms |
292 KB |
Output is correct |
29 |
Correct |
18 ms |
200 KB |
Output is correct |
30 |
Correct |
24 ms |
292 KB |
Output is correct |
31 |
Correct |
59 ms |
284 KB |
Output is correct |
32 |
Correct |
97 ms |
332 KB |
Output is correct |
33 |
Correct |
190 ms |
288 KB |
Output is correct |
34 |
Correct |
224 ms |
432 KB |
Output is correct |
35 |
Correct |
230 ms |
420 KB |
Output is correct |
36 |
Correct |
323 ms |
372 KB |
Output is correct |
37 |
Correct |
314 ms |
368 KB |
Output is correct |
38 |
Correct |
220 ms |
376 KB |
Output is correct |
39 |
Correct |
234 ms |
412 KB |
Output is correct |
40 |
Correct |
241 ms |
296 KB |
Output is correct |
41 |
Correct |
258 ms |
472 KB |
Output is correct |
42 |
Correct |
257 ms |
424 KB |
Output is correct |
43 |
Correct |
305 ms |
364 KB |
Output is correct |
44 |
Correct |
230 ms |
304 KB |
Output is correct |
45 |
Correct |
249 ms |
304 KB |
Output is correct |
46 |
Correct |
218 ms |
368 KB |
Output is correct |
47 |
Correct |
222 ms |
368 KB |
Output is correct |
48 |
Correct |
211 ms |
364 KB |
Output is correct |
49 |
Correct |
256 ms |
364 KB |
Output is correct |
50 |
Correct |
243 ms |
320 KB |
Output is correct |
51 |
Correct |
224 ms |
372 KB |
Output is correct |
52 |
Correct |
229 ms |
292 KB |
Output is correct |
53 |
Correct |
204 ms |
308 KB |
Output is correct |
54 |
Correct |
180 ms |
300 KB |
Output is correct |
55 |
Correct |
233 ms |
376 KB |
Output is correct |
56 |
Correct |
244 ms |
304 KB |
Output is correct |
57 |
Correct |
246 ms |
288 KB |
Output is correct |
58 |
Correct |
222 ms |
372 KB |
Output is correct |
59 |
Correct |
237 ms |
372 KB |
Output is correct |
60 |
Correct |
232 ms |
448 KB |
Output is correct |