#include "xylophone.h"
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int, int> pii;
int n;
int dnc(int s, int e) {
int m = (s + e) / 2;
int ret;
if ((ret = query(s, m)) == n - 1) return dnc(s, m);
else if (query(m + 1, e) == n - 1) return dnc(m + 1, e);
int i = s, j = m;
while (i < j) {
int d = (i + j + 1) / 2;
if (query(d, e) == n - 1) i = d;
else j = d - 1;
}
return i;
}
int q(int x, int y) {
static map<pii, int> mp;
if (mp.find(pii(x, y)) != mp.end()) return mp[pii(x, y)];
return mp[pii(x, y)] = query(x, y);
}
static int a[5001];
void solve(int N) {
n = N;
a[1] = 0;
a[2] = q(1, 2);
for (int i = 2; i < n; ++i) {
if (q(i - 1, i + 1) != q(i - 1, i) + q(i, i + 1)) {
if (a[i - 1] < a[i]) a[i + 1] = a[i] - q(i, i + 1);
else a[i + 1] = a[i] + q(i, i + 1);
}
else {
if (a[i - 1] < a[i]) a[i + 1] = a[i] + q(i, i + 1);
else a[i + 1] = a[i] - q(i, i + 1);
}
}
int i = min_element(a + 1, a + (n + 1)) - a;
int j = min_element(a + 1, a + (n + 1), greater<int>()) - a;
if (i > j) {
for (int i = 1; i <= n; ++i) a[i] = -a[i];
}
int x = (*min_element(a + 1, a + (n + 1))) - 1;
for (int i = 1; i <= n; ++i) {
answer(i, a[i] - x);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
420 KB |
Output is correct |
4 |
Correct |
5 ms |
432 KB |
Output is correct |
5 |
Correct |
4 ms |
600 KB |
Output is correct |
6 |
Correct |
6 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
4 ms |
600 KB |
Output is correct |
11 |
Correct |
23 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
6 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
420 KB |
Output is correct |
4 |
Correct |
5 ms |
432 KB |
Output is correct |
5 |
Correct |
4 ms |
600 KB |
Output is correct |
6 |
Correct |
6 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
4 ms |
600 KB |
Output is correct |
11 |
Correct |
23 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
6 ms |
600 KB |
Output is correct |
16 |
Correct |
5 ms |
600 KB |
Output is correct |
17 |
Correct |
14 ms |
600 KB |
Output is correct |
18 |
Correct |
22 ms |
600 KB |
Output is correct |
19 |
Correct |
23 ms |
600 KB |
Output is correct |
20 |
Correct |
25 ms |
600 KB |
Output is correct |
21 |
Correct |
24 ms |
600 KB |
Output is correct |
22 |
Correct |
12 ms |
688 KB |
Output is correct |
23 |
Correct |
23 ms |
688 KB |
Output is correct |
24 |
Correct |
11 ms |
688 KB |
Output is correct |
25 |
Correct |
11 ms |
688 KB |
Output is correct |
26 |
Correct |
26 ms |
688 KB |
Output is correct |
27 |
Correct |
21 ms |
688 KB |
Output is correct |
28 |
Correct |
21 ms |
688 KB |
Output is correct |
29 |
Correct |
19 ms |
688 KB |
Output is correct |
30 |
Correct |
10 ms |
688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
420 KB |
Output is correct |
4 |
Correct |
5 ms |
432 KB |
Output is correct |
5 |
Correct |
4 ms |
600 KB |
Output is correct |
6 |
Correct |
6 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
4 ms |
600 KB |
Output is correct |
11 |
Correct |
23 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
6 ms |
600 KB |
Output is correct |
16 |
Correct |
5 ms |
600 KB |
Output is correct |
17 |
Correct |
14 ms |
600 KB |
Output is correct |
18 |
Correct |
22 ms |
600 KB |
Output is correct |
19 |
Correct |
23 ms |
600 KB |
Output is correct |
20 |
Correct |
25 ms |
600 KB |
Output is correct |
21 |
Correct |
24 ms |
600 KB |
Output is correct |
22 |
Correct |
12 ms |
688 KB |
Output is correct |
23 |
Correct |
23 ms |
688 KB |
Output is correct |
24 |
Correct |
11 ms |
688 KB |
Output is correct |
25 |
Correct |
11 ms |
688 KB |
Output is correct |
26 |
Correct |
26 ms |
688 KB |
Output is correct |
27 |
Correct |
21 ms |
688 KB |
Output is correct |
28 |
Correct |
21 ms |
688 KB |
Output is correct |
29 |
Correct |
19 ms |
688 KB |
Output is correct |
30 |
Correct |
10 ms |
688 KB |
Output is correct |
31 |
Correct |
22 ms |
812 KB |
Output is correct |
32 |
Correct |
67 ms |
884 KB |
Output is correct |
33 |
Correct |
97 ms |
1084 KB |
Output is correct |
34 |
Correct |
102 ms |
1356 KB |
Output is correct |
35 |
Correct |
99 ms |
1356 KB |
Output is correct |
36 |
Correct |
74 ms |
1356 KB |
Output is correct |
37 |
Correct |
105 ms |
1356 KB |
Output is correct |
38 |
Correct |
104 ms |
1356 KB |
Output is correct |
39 |
Correct |
110 ms |
1356 KB |
Output is correct |
40 |
Correct |
103 ms |
1356 KB |
Output is correct |
41 |
Correct |
110 ms |
1356 KB |
Output is correct |
42 |
Correct |
86 ms |
1356 KB |
Output is correct |
43 |
Correct |
101 ms |
1356 KB |
Output is correct |
44 |
Correct |
101 ms |
1356 KB |
Output is correct |
45 |
Correct |
109 ms |
1356 KB |
Output is correct |
46 |
Correct |
94 ms |
1356 KB |
Output is correct |
47 |
Correct |
57 ms |
1356 KB |
Output is correct |
48 |
Correct |
136 ms |
1356 KB |
Output is correct |
49 |
Correct |
106 ms |
1356 KB |
Output is correct |
50 |
Correct |
90 ms |
1356 KB |
Output is correct |
51 |
Correct |
108 ms |
1356 KB |
Output is correct |
52 |
Correct |
92 ms |
1356 KB |
Output is correct |
53 |
Correct |
98 ms |
1356 KB |
Output is correct |
54 |
Correct |
96 ms |
1356 KB |
Output is correct |
55 |
Correct |
46 ms |
1356 KB |
Output is correct |
56 |
Correct |
83 ms |
1356 KB |
Output is correct |
57 |
Correct |
88 ms |
1356 KB |
Output is correct |
58 |
Correct |
101 ms |
1356 KB |
Output is correct |
59 |
Correct |
87 ms |
1356 KB |
Output is correct |
60 |
Correct |
103 ms |
1356 KB |
Output is correct |