#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
void solve(int N) {
vector<int> A(N+1);
A[1] = 0; A[2] = query(1, 2);
for (int i = 2; i < N; i++)
{
int d13 = query(i-1, i+1), d23 = query(i, i+1);
int d12 = abs(A[i]-A[i-1]); int sign = (A[i]-A[i-1])/d12;
if (d13 == d12 + d23) A[i+1] = A[i] + sign * d23;
else A[i+1] = A[i] - sign * d23;
}
int idMin = min_element(A.begin()+1, A.end()) - A.begin(), idMax = max_element(A.begin()+1, A.end()) - A.begin();
if (idMin > idMax) {swap(idMin, idMax); for (auto &x : A) x = -x;}
int aux = A[idMin];
for (auto &x : A) x += 1-aux;
for (int i = 1; i <= N; i++) answer(i, A[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
7 ms |
336 KB |
Output is correct |
17 |
Correct |
11 ms |
336 KB |
Output is correct |
18 |
Correct |
24 ms |
336 KB |
Output is correct |
19 |
Correct |
31 ms |
336 KB |
Output is correct |
20 |
Correct |
32 ms |
336 KB |
Output is correct |
21 |
Correct |
23 ms |
336 KB |
Output is correct |
22 |
Correct |
28 ms |
336 KB |
Output is correct |
23 |
Correct |
28 ms |
336 KB |
Output is correct |
24 |
Correct |
30 ms |
436 KB |
Output is correct |
25 |
Correct |
31 ms |
336 KB |
Output is correct |
26 |
Correct |
29 ms |
336 KB |
Output is correct |
27 |
Correct |
25 ms |
336 KB |
Output is correct |
28 |
Correct |
31 ms |
336 KB |
Output is correct |
29 |
Correct |
35 ms |
336 KB |
Output is correct |
30 |
Correct |
31 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
5 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
7 ms |
336 KB |
Output is correct |
17 |
Correct |
11 ms |
336 KB |
Output is correct |
18 |
Correct |
24 ms |
336 KB |
Output is correct |
19 |
Correct |
31 ms |
336 KB |
Output is correct |
20 |
Correct |
32 ms |
336 KB |
Output is correct |
21 |
Correct |
23 ms |
336 KB |
Output is correct |
22 |
Correct |
28 ms |
336 KB |
Output is correct |
23 |
Correct |
28 ms |
336 KB |
Output is correct |
24 |
Correct |
30 ms |
436 KB |
Output is correct |
25 |
Correct |
31 ms |
336 KB |
Output is correct |
26 |
Correct |
29 ms |
336 KB |
Output is correct |
27 |
Correct |
25 ms |
336 KB |
Output is correct |
28 |
Correct |
31 ms |
336 KB |
Output is correct |
29 |
Correct |
35 ms |
336 KB |
Output is correct |
30 |
Correct |
31 ms |
336 KB |
Output is correct |
31 |
Correct |
69 ms |
336 KB |
Output is correct |
32 |
Correct |
101 ms |
336 KB |
Output is correct |
33 |
Correct |
152 ms |
336 KB |
Output is correct |
34 |
Correct |
186 ms |
336 KB |
Output is correct |
35 |
Correct |
189 ms |
336 KB |
Output is correct |
36 |
Correct |
180 ms |
336 KB |
Output is correct |
37 |
Correct |
182 ms |
336 KB |
Output is correct |
38 |
Correct |
202 ms |
336 KB |
Output is correct |
39 |
Correct |
183 ms |
448 KB |
Output is correct |
40 |
Correct |
175 ms |
336 KB |
Output is correct |
41 |
Correct |
184 ms |
336 KB |
Output is correct |
42 |
Correct |
160 ms |
336 KB |
Output is correct |
43 |
Correct |
200 ms |
336 KB |
Output is correct |
44 |
Correct |
177 ms |
336 KB |
Output is correct |
45 |
Correct |
182 ms |
336 KB |
Output is correct |
46 |
Correct |
194 ms |
336 KB |
Output is correct |
47 |
Correct |
174 ms |
336 KB |
Output is correct |
48 |
Correct |
189 ms |
336 KB |
Output is correct |
49 |
Correct |
178 ms |
336 KB |
Output is correct |
50 |
Correct |
192 ms |
336 KB |
Output is correct |
51 |
Correct |
170 ms |
336 KB |
Output is correct |
52 |
Correct |
185 ms |
448 KB |
Output is correct |
53 |
Correct |
180 ms |
448 KB |
Output is correct |
54 |
Correct |
178 ms |
504 KB |
Output is correct |
55 |
Correct |
170 ms |
336 KB |
Output is correct |
56 |
Correct |
182 ms |
336 KB |
Output is correct |
57 |
Correct |
184 ms |
336 KB |
Output is correct |
58 |
Correct |
180 ms |
584 KB |
Output is correct |
59 |
Correct |
185 ms |
336 KB |
Output is correct |
60 |
Correct |
173 ms |
336 KB |
Output is correct |