#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#define ll long long
ll d2[(ll)1e5 + 100], d3[(ll)1e5 + 100], a[(ll)1e5 + 100], pos[(ll)1e5 + 100];
bool check(ll x, ll n){
a[2] = x;
for(int i = 3; i <= n;i++){
if(d3[i] == d2[i-1]){
if(a[i-1] < a[i-2]){
a[i] = a[i-1] + d2[i];
}
else a[i] = a[i-1] - d2[i];
}
else{
if(a[i-2] < a[i-1]){
if(d2[i-1] + d2[i] == d3[i]){
a[i] = a[i-1] + d2[i];
}
else{
a[i] = a[i-1] - d2[i];
}
}
else{
if(d2[i] == d3[i]){
a[i] = a[i-1] + d2[i];
}
else a[i] = a[i-2] - d3[i];
}
}
}
for(int i = 1; i <= n;i++) pos[i] = 0;
for(int i = 1; i <= n;i++) {
if(a[i] < 0) return 0;
pos[a[i]] = i;
}
ll ok = (pos[1] < pos[n]);
for(int i = 1; i <= n;i++) ok &= (pos[i] > 0);
if(ok){
for(int i = 1; i <= n;i++) answer(i, a[i]);
return 1;
}
else return 0;
}
void solve(int n){
for(int i = 2; i <= n;i++) d2[i] = query(i - 1, i);
for(int i = 3; i <= n;i++) d3[i] = query(i - 2, i);
for(int val = 1; val <= n;val++){
for(int i = 1; i <= n;i++) pos[i] = 0;
a[1] = val;
if(check(a[1] + d2[2], n)) return;
if(check(a[1] - d2[2], n)) return;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2436 KB |
Output is correct |
7 |
Correct |
1 ms |
2496 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 |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2436 KB |
Output is correct |
7 |
Correct |
1 ms |
2496 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 |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2496 KB |
Output is correct |
16 |
Correct |
3 ms |
2484 KB |
Output is correct |
17 |
Correct |
5 ms |
2648 KB |
Output is correct |
18 |
Correct |
7 ms |
2392 KB |
Output is correct |
19 |
Correct |
17 ms |
2504 KB |
Output is correct |
20 |
Correct |
17 ms |
2648 KB |
Output is correct |
21 |
Correct |
13 ms |
2392 KB |
Output is correct |
22 |
Correct |
13 ms |
2392 KB |
Output is correct |
23 |
Correct |
13 ms |
2504 KB |
Output is correct |
24 |
Correct |
11 ms |
2392 KB |
Output is correct |
25 |
Correct |
6 ms |
2756 KB |
Output is correct |
26 |
Correct |
17 ms |
2388 KB |
Output is correct |
27 |
Correct |
8 ms |
2392 KB |
Output is correct |
28 |
Correct |
13 ms |
2392 KB |
Output is correct |
29 |
Correct |
14 ms |
2648 KB |
Output is correct |
30 |
Correct |
7 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2436 KB |
Output is correct |
7 |
Correct |
1 ms |
2496 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 |
2 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2496 KB |
Output is correct |
16 |
Correct |
3 ms |
2484 KB |
Output is correct |
17 |
Correct |
5 ms |
2648 KB |
Output is correct |
18 |
Correct |
7 ms |
2392 KB |
Output is correct |
19 |
Correct |
17 ms |
2504 KB |
Output is correct |
20 |
Correct |
17 ms |
2648 KB |
Output is correct |
21 |
Correct |
13 ms |
2392 KB |
Output is correct |
22 |
Correct |
13 ms |
2392 KB |
Output is correct |
23 |
Correct |
13 ms |
2504 KB |
Output is correct |
24 |
Correct |
11 ms |
2392 KB |
Output is correct |
25 |
Correct |
6 ms |
2756 KB |
Output is correct |
26 |
Correct |
17 ms |
2388 KB |
Output is correct |
27 |
Correct |
8 ms |
2392 KB |
Output is correct |
28 |
Correct |
13 ms |
2392 KB |
Output is correct |
29 |
Correct |
14 ms |
2648 KB |
Output is correct |
30 |
Correct |
7 ms |
2392 KB |
Output is correct |
31 |
Correct |
25 ms |
2512 KB |
Output is correct |
32 |
Correct |
75 ms |
2500 KB |
Output is correct |
33 |
Correct |
76 ms |
2652 KB |
Output is correct |
34 |
Correct |
109 ms |
2504 KB |
Output is correct |
35 |
Correct |
128 ms |
2764 KB |
Output is correct |
36 |
Correct |
61 ms |
2740 KB |
Output is correct |
37 |
Correct |
95 ms |
2764 KB |
Output is correct |
38 |
Correct |
47 ms |
2380 KB |
Output is correct |
39 |
Correct |
65 ms |
2680 KB |
Output is correct |
40 |
Correct |
80 ms |
2744 KB |
Output is correct |
41 |
Correct |
110 ms |
2384 KB |
Output is correct |
42 |
Correct |
52 ms |
2748 KB |
Output is correct |
43 |
Correct |
94 ms |
2520 KB |
Output is correct |
44 |
Correct |
61 ms |
2748 KB |
Output is correct |
45 |
Correct |
85 ms |
2512 KB |
Output is correct |
46 |
Correct |
177 ms |
2744 KB |
Output is correct |
47 |
Correct |
178 ms |
2492 KB |
Output is correct |
48 |
Correct |
73 ms |
2764 KB |
Output is correct |
49 |
Correct |
163 ms |
2640 KB |
Output is correct |
50 |
Correct |
149 ms |
2512 KB |
Output is correct |
51 |
Correct |
100 ms |
2560 KB |
Output is correct |
52 |
Correct |
70 ms |
2512 KB |
Output is correct |
53 |
Correct |
166 ms |
2560 KB |
Output is correct |
54 |
Correct |
132 ms |
2756 KB |
Output is correct |
55 |
Correct |
156 ms |
2764 KB |
Output is correct |
56 |
Correct |
165 ms |
2572 KB |
Output is correct |
57 |
Correct |
147 ms |
2552 KB |
Output is correct |
58 |
Correct |
190 ms |
2816 KB |
Output is correct |
59 |
Correct |
96 ms |
2560 KB |
Output is correct |
60 |
Correct |
96 ms |
2520 KB |
Output is correct |