#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int a1[5001], a2[5001];
void solve(int N) {
int n = N;
int pos1=1;
a1[pos1] = 1;
a2[pos1] = 1;
a1[pos1+1] = 1-query(pos1, pos1+1);
a2[pos1+1] = query(pos1, pos1+1) + 1;
for (int pt = pos1+2; pt<=n; pt++) {
int q1 = query(pt-1, pt), q2 = query(pt-2, pt);
int d1 = abs(a1[pt-1] - a1[pt-2]);
int d = q1;
if (a1[pt-2] < a1[pt-1]) {
if (q2 == d + d1) a1[pt] = a1[pt-1] + d;
else a1[pt] = a1[pt-1] - d;
} else {
if (q2 == d + d1) a1[pt] = a1[pt-1] - d;
else a1[pt] = a1[pt-1] + d;
}
d1 = abs(a2[pt-1] - a2[pt-2]);
if (a2[pt-2] < a2[pt-1]) {
if (q2 == d + d1) a2[pt] = a2[pt-1] + d;
else a2[pt] = a2[pt-1] - d;
} else {
if (q2 == d + d1) a2[pt] = a2[pt-1] - d;
else a2[pt] = a2[pt-1] + d;
}
}
int mn = 1e9;
for (int i=1; i<=n; i++) mn = min(mn, a1[i]);
for (int i=1; i<=n; i++) a1[i] -= mn-1;
mn = 1e9;
for (int i=1; i<=n; i++) mn = min(mn, a2[i]);
for (int i=1; i<=n; i++) a2[i] -= mn-1;
// int pos1=n;
// for (; pos1>=1; pos1--) {
// int value = query(pos1, n);
// if (value == n-1) break;
// }
// a[pos1] = 1;
// a[pos1+1] = query(pos1, pos1+1) + 1;
// for (int pt = pos1+2; pt<=n; pt++) {
// int d1 = abs(a[pt-1] - a[pt-2]);
// int d = query(pt-1, pt);
// if (a[pt-2] < a[pt-1]) {
// if (query(pt-2, pt) == d + d1) a[pt] = a[pt-1] + d;
// else a[pt] = a[pt-1] - d;
// } else {
// if (query(pt-2, pt) == d + d1) a[pt] = a[pt-1] - d;
// else a[pt] = a[pt-1] + d;
// }
// }
// for (int pt = pos1-1; pt>=1; pt--) {
// int d1 = abs(a[pt+1] - a[pt+2]);
// int d = query(pt, pt+1);
// if (a[pt+2] < a[pt+1]) {
// if (query(pt, pt+2) == d + d1) a[pt] = a[pt+1] + d;
// else a[pt] = a[pt+1] - d;
// } else {
// if (query(pt, pt+2) == d + d1) a[pt] = a[pt+1] - d;
// else a[pt] = a[pt+1] + d;
// }
// }
bool a1_ac = true;
bool found1 = false;
for (int i=1; i<=n; i++) {
if (a1[i] == 1) found1 = true;
if (a1[i] == n and !found1) a1_ac = false;
}
for(int i = 1; i <= N; i++) {
answer(i, a1_ac ? a1[i] : a2[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 |
3 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 |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
4 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 |
3 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 |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
8 ms |
336 KB |
Output is correct |
17 |
Correct |
13 ms |
336 KB |
Output is correct |
18 |
Correct |
27 ms |
436 KB |
Output is correct |
19 |
Correct |
32 ms |
588 KB |
Output is correct |
20 |
Correct |
32 ms |
584 KB |
Output is correct |
21 |
Correct |
31 ms |
436 KB |
Output is correct |
22 |
Correct |
31 ms |
440 KB |
Output is correct |
23 |
Correct |
32 ms |
444 KB |
Output is correct |
24 |
Correct |
34 ms |
436 KB |
Output is correct |
25 |
Correct |
32 ms |
440 KB |
Output is correct |
26 |
Correct |
34 ms |
696 KB |
Output is correct |
27 |
Correct |
32 ms |
692 KB |
Output is correct |
28 |
Correct |
30 ms |
688 KB |
Output is correct |
29 |
Correct |
39 ms |
444 KB |
Output is correct |
30 |
Correct |
25 ms |
440 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 |
3 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 |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
8 ms |
336 KB |
Output is correct |
17 |
Correct |
13 ms |
336 KB |
Output is correct |
18 |
Correct |
27 ms |
436 KB |
Output is correct |
19 |
Correct |
32 ms |
588 KB |
Output is correct |
20 |
Correct |
32 ms |
584 KB |
Output is correct |
21 |
Correct |
31 ms |
436 KB |
Output is correct |
22 |
Correct |
31 ms |
440 KB |
Output is correct |
23 |
Correct |
32 ms |
444 KB |
Output is correct |
24 |
Correct |
34 ms |
436 KB |
Output is correct |
25 |
Correct |
32 ms |
440 KB |
Output is correct |
26 |
Correct |
34 ms |
696 KB |
Output is correct |
27 |
Correct |
32 ms |
692 KB |
Output is correct |
28 |
Correct |
30 ms |
688 KB |
Output is correct |
29 |
Correct |
39 ms |
444 KB |
Output is correct |
30 |
Correct |
25 ms |
440 KB |
Output is correct |
31 |
Correct |
77 ms |
692 KB |
Output is correct |
32 |
Correct |
105 ms |
696 KB |
Output is correct |
33 |
Correct |
170 ms |
440 KB |
Output is correct |
34 |
Correct |
185 ms |
468 KB |
Output is correct |
35 |
Correct |
184 ms |
436 KB |
Output is correct |
36 |
Correct |
178 ms |
712 KB |
Output is correct |
37 |
Correct |
158 ms |
440 KB |
Output is correct |
38 |
Correct |
172 ms |
596 KB |
Output is correct |
39 |
Correct |
178 ms |
464 KB |
Output is correct |
40 |
Correct |
162 ms |
704 KB |
Output is correct |
41 |
Correct |
173 ms |
952 KB |
Output is correct |
42 |
Correct |
145 ms |
700 KB |
Output is correct |
43 |
Correct |
178 ms |
460 KB |
Output is correct |
44 |
Correct |
182 ms |
704 KB |
Output is correct |
45 |
Correct |
183 ms |
444 KB |
Output is correct |
46 |
Correct |
167 ms |
464 KB |
Output is correct |
47 |
Correct |
186 ms |
588 KB |
Output is correct |
48 |
Correct |
172 ms |
588 KB |
Output is correct |
49 |
Correct |
176 ms |
844 KB |
Output is correct |
50 |
Correct |
162 ms |
704 KB |
Output is correct |
51 |
Correct |
196 ms |
956 KB |
Output is correct |
52 |
Correct |
157 ms |
456 KB |
Output is correct |
53 |
Correct |
201 ms |
708 KB |
Output is correct |
54 |
Correct |
196 ms |
584 KB |
Output is correct |
55 |
Correct |
188 ms |
712 KB |
Output is correct |
56 |
Correct |
186 ms |
456 KB |
Output is correct |
57 |
Correct |
155 ms |
712 KB |
Output is correct |
58 |
Correct |
179 ms |
700 KB |
Output is correct |
59 |
Correct |
187 ms |
584 KB |
Output is correct |
60 |
Correct |
184 ms |
708 KB |
Output is correct |