#include "xylophone.h"
#include <algorithm>
#define qry query
using namespace std;
int n;
bool col[5050];
int a[5050];
int d(int a, int b, int c)
{
return max(a, max(b, c)) - min(a, min(b, c));
}
void solve(int N) {
n = N;
int l = 1, r = n - 1, i1 = n - 1;
while (l <= r)
{
int mid = (l + r) / 2;
if (qry(mid, n) == n - 1) i1 = mid, l = mid + 1;
else r = mid - 1;
}
a[i1] = 1;
//printf("%d\n", i1);
for (int i = i1 - 1; i > 0; i--)
{
int sm = qry(i, i + 1);
if (a[i + 1] - sm < 1 || col[a[i + 1] - sm]) a[i] = a[i + 1] + sm;
else if (a[i + 1] + sm > n || col[a[i + 1] + sm]) a[i] = a[i + 1] - sm;
else
{
int sm1 = qry(i, i + 2);
if (d(a[i + 1], a[i + 2], a[i + 1] + sm) == sm1) a[i] = a[i + 1] + sm;
else a[i] = a[i + 1] - sm;
}
col[a[i]] = 1;
}
for (int i = i1 + 1; i <= n; i++)
{
int sm = qry(i - 1, i);
if (a[i - 1] - sm < 1 || col[a[i - 1] - sm]) a[i] = a[i - 1] + sm;
else if (a[i - 1] + sm > n || col[a[i - 1] + sm]) a[i] = a[i - 1] - sm;
else
{
int sm1 = qry(i - 2, i);
if (d(a[i - 1], a[i - 2], a[i - 1] + sm) == sm1) a[i] = a[i - 1] + sm;
else a[i] = a[i - 1] - sm;
}
col[a[i]] = 1;
}
for (int i = 1; i <= n; i++) answer(i, a[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
364 KB |
Output is correct |
17 |
Correct |
6 ms |
364 KB |
Output is correct |
18 |
Correct |
10 ms |
364 KB |
Output is correct |
19 |
Correct |
12 ms |
364 KB |
Output is correct |
20 |
Correct |
11 ms |
492 KB |
Output is correct |
21 |
Correct |
16 ms |
364 KB |
Output is correct |
22 |
Correct |
16 ms |
364 KB |
Output is correct |
23 |
Correct |
10 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
25 |
Correct |
10 ms |
364 KB |
Output is correct |
26 |
Correct |
17 ms |
256 KB |
Output is correct |
27 |
Correct |
12 ms |
492 KB |
Output is correct |
28 |
Correct |
12 ms |
364 KB |
Output is correct |
29 |
Correct |
16 ms |
492 KB |
Output is correct |
30 |
Correct |
14 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
364 KB |
Output is correct |
17 |
Correct |
6 ms |
364 KB |
Output is correct |
18 |
Correct |
10 ms |
364 KB |
Output is correct |
19 |
Correct |
12 ms |
364 KB |
Output is correct |
20 |
Correct |
11 ms |
492 KB |
Output is correct |
21 |
Correct |
16 ms |
364 KB |
Output is correct |
22 |
Correct |
16 ms |
364 KB |
Output is correct |
23 |
Correct |
10 ms |
364 KB |
Output is correct |
24 |
Correct |
9 ms |
364 KB |
Output is correct |
25 |
Correct |
10 ms |
364 KB |
Output is correct |
26 |
Correct |
17 ms |
256 KB |
Output is correct |
27 |
Correct |
12 ms |
492 KB |
Output is correct |
28 |
Correct |
12 ms |
364 KB |
Output is correct |
29 |
Correct |
16 ms |
492 KB |
Output is correct |
30 |
Correct |
14 ms |
364 KB |
Output is correct |
31 |
Correct |
28 ms |
496 KB |
Output is correct |
32 |
Correct |
35 ms |
364 KB |
Output is correct |
33 |
Correct |
61 ms |
364 KB |
Output is correct |
34 |
Correct |
51 ms |
364 KB |
Output is correct |
35 |
Correct |
58 ms |
384 KB |
Output is correct |
36 |
Correct |
40 ms |
364 KB |
Output is correct |
37 |
Correct |
61 ms |
492 KB |
Output is correct |
38 |
Correct |
49 ms |
364 KB |
Output is correct |
39 |
Correct |
53 ms |
364 KB |
Output is correct |
40 |
Correct |
65 ms |
364 KB |
Output is correct |
41 |
Correct |
58 ms |
492 KB |
Output is correct |
42 |
Correct |
63 ms |
364 KB |
Output is correct |
43 |
Correct |
63 ms |
492 KB |
Output is correct |
44 |
Correct |
41 ms |
488 KB |
Output is correct |
45 |
Correct |
79 ms |
364 KB |
Output is correct |
46 |
Correct |
79 ms |
364 KB |
Output is correct |
47 |
Correct |
59 ms |
364 KB |
Output is correct |
48 |
Correct |
66 ms |
492 KB |
Output is correct |
49 |
Correct |
76 ms |
364 KB |
Output is correct |
50 |
Correct |
78 ms |
364 KB |
Output is correct |
51 |
Correct |
76 ms |
364 KB |
Output is correct |
52 |
Correct |
57 ms |
364 KB |
Output is correct |
53 |
Correct |
81 ms |
364 KB |
Output is correct |
54 |
Correct |
56 ms |
496 KB |
Output is correct |
55 |
Correct |
61 ms |
364 KB |
Output is correct |
56 |
Correct |
77 ms |
620 KB |
Output is correct |
57 |
Correct |
52 ms |
492 KB |
Output is correct |
58 |
Correct |
44 ms |
620 KB |
Output is correct |
59 |
Correct |
56 ms |
492 KB |
Output is correct |
60 |
Correct |
78 ms |
364 KB |
Output is correct |