#include "xylophone.h"
#include <iostream>
#include <algorithm>
using namespace std;
static int A[5050];
void solve(int N) {
// gaps of 1 and 2
int d1[5050];
int d2[5050];
// O(2N) queries
for (int i = 1; i < N; i++) {
d1[i] = query(i, i + 1);
if (i < N - 1)
d2[i] = query(i, i + 2);
}
// change direction?
bool change[5050];
for (int i = 1; i < N - 1; i++) {
change[i] = !(d1[i] + d1[i + 1] == d2[i]);
}
int number = 0;
int direction = 1;
A[0] = number;
for (int i = 1; i < N; i++) {
number += d1[i] * direction;
A[i] = number;
if (i < N - 1 && change[i]) direction *= -1;
}
// min, max
int min_ = 5001, min_index = 0;
int max_ = -1, max_index = 0;
for (int i = 0; i < N; i++) {
int a = A[i];
if (a < min_) {
min_ = a;
min_index = i;
}
if (a > max_) {
max_ = a;
max_index = i;
}
}
// offset
min_--;
for (int i = 0; i < N; i++) {
A[i] -= min_;
}
// reverse
if (min_index > max_index) {
for (int i = 0; i < N; i++) {
A[i] = N - A[i] + 1;
}
}
// answer
for (int i = 1; i <= N; i++) {
answer(i, A[i - 1]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 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 |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 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 |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 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 |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 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 |
10 ms |
364 KB |
Output is correct |
18 |
Correct |
15 ms |
492 KB |
Output is correct |
19 |
Correct |
15 ms |
364 KB |
Output is correct |
20 |
Correct |
18 ms |
364 KB |
Output is correct |
21 |
Correct |
18 ms |
492 KB |
Output is correct |
22 |
Correct |
11 ms |
384 KB |
Output is correct |
23 |
Correct |
15 ms |
364 KB |
Output is correct |
24 |
Correct |
19 ms |
364 KB |
Output is correct |
25 |
Correct |
20 ms |
364 KB |
Output is correct |
26 |
Correct |
19 ms |
364 KB |
Output is correct |
27 |
Correct |
17 ms |
364 KB |
Output is correct |
28 |
Correct |
19 ms |
364 KB |
Output is correct |
29 |
Correct |
19 ms |
364 KB |
Output is correct |
30 |
Correct |
19 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 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 |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 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 |
10 ms |
364 KB |
Output is correct |
18 |
Correct |
15 ms |
492 KB |
Output is correct |
19 |
Correct |
15 ms |
364 KB |
Output is correct |
20 |
Correct |
18 ms |
364 KB |
Output is correct |
21 |
Correct |
18 ms |
492 KB |
Output is correct |
22 |
Correct |
11 ms |
384 KB |
Output is correct |
23 |
Correct |
15 ms |
364 KB |
Output is correct |
24 |
Correct |
19 ms |
364 KB |
Output is correct |
25 |
Correct |
20 ms |
364 KB |
Output is correct |
26 |
Correct |
19 ms |
364 KB |
Output is correct |
27 |
Correct |
17 ms |
364 KB |
Output is correct |
28 |
Correct |
19 ms |
364 KB |
Output is correct |
29 |
Correct |
19 ms |
364 KB |
Output is correct |
30 |
Correct |
19 ms |
384 KB |
Output is correct |
31 |
Correct |
39 ms |
364 KB |
Output is correct |
32 |
Correct |
54 ms |
364 KB |
Output is correct |
33 |
Correct |
75 ms |
364 KB |
Output is correct |
34 |
Correct |
87 ms |
364 KB |
Output is correct |
35 |
Correct |
72 ms |
492 KB |
Output is correct |
36 |
Correct |
86 ms |
364 KB |
Output is correct |
37 |
Correct |
75 ms |
364 KB |
Output is correct |
38 |
Correct |
91 ms |
364 KB |
Output is correct |
39 |
Correct |
79 ms |
492 KB |
Output is correct |
40 |
Correct |
104 ms |
364 KB |
Output is correct |
41 |
Correct |
79 ms |
620 KB |
Output is correct |
42 |
Correct |
64 ms |
492 KB |
Output is correct |
43 |
Correct |
80 ms |
364 KB |
Output is correct |
44 |
Correct |
113 ms |
364 KB |
Output is correct |
45 |
Correct |
99 ms |
492 KB |
Output is correct |
46 |
Correct |
99 ms |
364 KB |
Output is correct |
47 |
Correct |
95 ms |
364 KB |
Output is correct |
48 |
Correct |
101 ms |
492 KB |
Output is correct |
49 |
Correct |
52 ms |
384 KB |
Output is correct |
50 |
Correct |
131 ms |
364 KB |
Output is correct |
51 |
Correct |
87 ms |
492 KB |
Output is correct |
52 |
Correct |
129 ms |
364 KB |
Output is correct |
53 |
Correct |
129 ms |
364 KB |
Output is correct |
54 |
Correct |
99 ms |
364 KB |
Output is correct |
55 |
Correct |
111 ms |
500 KB |
Output is correct |
56 |
Correct |
119 ms |
492 KB |
Output is correct |
57 |
Correct |
81 ms |
384 KB |
Output is correct |
58 |
Correct |
102 ms |
620 KB |
Output is correct |
59 |
Correct |
91 ms |
364 KB |
Output is correct |
60 |
Correct |
128 ms |
492 KB |
Output is correct |