#include "xylophone.h"
#include <bits/stdc++.h>
static int A[5000];
int a[5010];
int q[5010][5010];
int qur(int a, int b) {
if (q[a][b] == -1) return q[a][b] = query(a, b);
else return q[a][b];
}
void solve(int n) {
memset(q, -1, sizeof q);
int fir = qur(1, 2);
for (int x = 1; x <= n; x++) {
a[1] = x;
for (int typ = -1; typ < 2; typ += 2) {
a[2] = fir * typ + x;
for (int i = 3; i <= n; i++) {
int x = qur(i - 1, i);
int y = qur(i - 2, i);
if (a[i - 1] < a[i - 2]) {
if (y == a[i - 2] - a[i - 1] + x) a[i] = a[i - 1] - x;
else if (x == y) a[i] = a[i - 1] + x;
else a[i] = a[i - 1] + x;
} else {
if (y == a[i - 1] - a[i - 2]) a[i] = a[i - 1] - x;
else if (x == y) a[i] = a[i - 1] - x;
else a[i] = a[i - 1] + x;
}
}
int s = -1;
bool flag = false;
for (int i = 1; i <= n; i++) {
if (a[i] == 1) s = i;
else if (a[i] == n) {
if (s != -1) flag = true;
else flag = false;
} else if (a[i] > n) {
flag = false;
break;
}
}
/**
for (int i = 1; i <= n; i++)
printf("%d ", a[i]);
printf("\n");
**/
if (flag) {
//printf("debug: ");
//for (int i = 1; i <= n; i++)
// printf("%d ", a[i]);
//printf("\n");
for (int i = 1; i <= n; i++)
answer(i, a[i]);
return;
}
}
}
}
Compilation message
xylophone.cpp:4:12: warning: 'A' defined but not used [-Wunused-variable]
static int A[5000];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
98680 KB |
Output is correct |
2 |
Correct |
80 ms |
98552 KB |
Output is correct |
3 |
Correct |
82 ms |
98552 KB |
Output is correct |
4 |
Correct |
84 ms |
98552 KB |
Output is correct |
5 |
Correct |
82 ms |
98424 KB |
Output is correct |
6 |
Correct |
82 ms |
98472 KB |
Output is correct |
7 |
Correct |
82 ms |
98452 KB |
Output is correct |
8 |
Correct |
83 ms |
98472 KB |
Output is correct |
9 |
Correct |
82 ms |
98552 KB |
Output is correct |
10 |
Correct |
85 ms |
98516 KB |
Output is correct |
11 |
Correct |
82 ms |
98552 KB |
Output is correct |
12 |
Correct |
96 ms |
98552 KB |
Output is correct |
13 |
Correct |
83 ms |
98472 KB |
Output is correct |
14 |
Correct |
84 ms |
98552 KB |
Output is correct |
15 |
Correct |
82 ms |
98552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
98680 KB |
Output is correct |
2 |
Correct |
80 ms |
98552 KB |
Output is correct |
3 |
Correct |
82 ms |
98552 KB |
Output is correct |
4 |
Correct |
84 ms |
98552 KB |
Output is correct |
5 |
Correct |
82 ms |
98424 KB |
Output is correct |
6 |
Correct |
82 ms |
98472 KB |
Output is correct |
7 |
Correct |
82 ms |
98452 KB |
Output is correct |
8 |
Correct |
83 ms |
98472 KB |
Output is correct |
9 |
Correct |
82 ms |
98552 KB |
Output is correct |
10 |
Correct |
85 ms |
98516 KB |
Output is correct |
11 |
Correct |
82 ms |
98552 KB |
Output is correct |
12 |
Correct |
96 ms |
98552 KB |
Output is correct |
13 |
Correct |
83 ms |
98472 KB |
Output is correct |
14 |
Correct |
84 ms |
98552 KB |
Output is correct |
15 |
Correct |
82 ms |
98552 KB |
Output is correct |
16 |
Correct |
86 ms |
98552 KB |
Output is correct |
17 |
Correct |
90 ms |
98552 KB |
Output is correct |
18 |
Correct |
104 ms |
98556 KB |
Output is correct |
19 |
Correct |
100 ms |
98680 KB |
Output is correct |
20 |
Correct |
111 ms |
98472 KB |
Output is correct |
21 |
Correct |
106 ms |
98552 KB |
Output is correct |
22 |
Correct |
110 ms |
98552 KB |
Output is correct |
23 |
Correct |
98 ms |
98600 KB |
Output is correct |
24 |
Correct |
96 ms |
98628 KB |
Output is correct |
25 |
Correct |
92 ms |
98640 KB |
Output is correct |
26 |
Correct |
106 ms |
98552 KB |
Output is correct |
27 |
Correct |
115 ms |
98552 KB |
Output is correct |
28 |
Correct |
97 ms |
98620 KB |
Output is correct |
29 |
Correct |
101 ms |
98688 KB |
Output is correct |
30 |
Correct |
103 ms |
98552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
98680 KB |
Output is correct |
2 |
Correct |
80 ms |
98552 KB |
Output is correct |
3 |
Correct |
82 ms |
98552 KB |
Output is correct |
4 |
Correct |
84 ms |
98552 KB |
Output is correct |
5 |
Correct |
82 ms |
98424 KB |
Output is correct |
6 |
Correct |
82 ms |
98472 KB |
Output is correct |
7 |
Correct |
82 ms |
98452 KB |
Output is correct |
8 |
Correct |
83 ms |
98472 KB |
Output is correct |
9 |
Correct |
82 ms |
98552 KB |
Output is correct |
10 |
Correct |
85 ms |
98516 KB |
Output is correct |
11 |
Correct |
82 ms |
98552 KB |
Output is correct |
12 |
Correct |
96 ms |
98552 KB |
Output is correct |
13 |
Correct |
83 ms |
98472 KB |
Output is correct |
14 |
Correct |
84 ms |
98552 KB |
Output is correct |
15 |
Correct |
82 ms |
98552 KB |
Output is correct |
16 |
Correct |
86 ms |
98552 KB |
Output is correct |
17 |
Correct |
90 ms |
98552 KB |
Output is correct |
18 |
Correct |
104 ms |
98556 KB |
Output is correct |
19 |
Correct |
100 ms |
98680 KB |
Output is correct |
20 |
Correct |
111 ms |
98472 KB |
Output is correct |
21 |
Correct |
106 ms |
98552 KB |
Output is correct |
22 |
Correct |
110 ms |
98552 KB |
Output is correct |
23 |
Correct |
98 ms |
98600 KB |
Output is correct |
24 |
Correct |
96 ms |
98628 KB |
Output is correct |
25 |
Correct |
92 ms |
98640 KB |
Output is correct |
26 |
Correct |
106 ms |
98552 KB |
Output is correct |
27 |
Correct |
115 ms |
98552 KB |
Output is correct |
28 |
Correct |
97 ms |
98620 KB |
Output is correct |
29 |
Correct |
101 ms |
98688 KB |
Output is correct |
30 |
Correct |
103 ms |
98552 KB |
Output is correct |
31 |
Correct |
150 ms |
98656 KB |
Output is correct |
32 |
Correct |
384 ms |
98680 KB |
Output is correct |
33 |
Correct |
432 ms |
98680 KB |
Output is correct |
34 |
Correct |
664 ms |
98684 KB |
Output is correct |
35 |
Correct |
672 ms |
98728 KB |
Output is correct |
36 |
Correct |
182 ms |
98688 KB |
Output is correct |
37 |
Correct |
553 ms |
98680 KB |
Output is correct |
38 |
Correct |
178 ms |
98688 KB |
Output is correct |
39 |
Correct |
280 ms |
98564 KB |
Output is correct |
40 |
Correct |
499 ms |
98688 KB |
Output is correct |
41 |
Correct |
706 ms |
98592 KB |
Output is correct |
42 |
Correct |
186 ms |
98552 KB |
Output is correct |
43 |
Correct |
506 ms |
98680 KB |
Output is correct |
44 |
Correct |
183 ms |
98752 KB |
Output is correct |
45 |
Correct |
362 ms |
98556 KB |
Output is correct |
46 |
Correct |
766 ms |
98680 KB |
Output is correct |
47 |
Correct |
817 ms |
98684 KB |
Output is correct |
48 |
Correct |
156 ms |
98696 KB |
Output is correct |
49 |
Correct |
795 ms |
98684 KB |
Output is correct |
50 |
Correct |
763 ms |
98688 KB |
Output is correct |
51 |
Correct |
445 ms |
98552 KB |
Output is correct |
52 |
Correct |
283 ms |
98560 KB |
Output is correct |
53 |
Correct |
862 ms |
98684 KB |
Output is correct |
54 |
Correct |
724 ms |
98680 KB |
Output is correct |
55 |
Correct |
879 ms |
98620 KB |
Output is correct |
56 |
Correct |
908 ms |
98552 KB |
Output is correct |
57 |
Correct |
781 ms |
98572 KB |
Output is correct |
58 |
Correct |
1067 ms |
98788 KB |
Output is correct |
59 |
Correct |
589 ms |
98636 KB |
Output is correct |
60 |
Correct |
553 ms |
98552 KB |
Output is correct |