#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
pair<int, int> GetSpecial(pair<int, int> a, pair<int, int> b) {
/* List of classes determined by 2 special colors
Case 1:
000 000 000
000 000 000
110 101 011
000 000 000
110 101 011
000 000 000
110 101 011
000 000 000
000 000 000
Case 2:
000 000 000
001 010 100
100 001 010
001 010 100
100 001 010
000 000 000
100 001 010
000 000 000
001 010 100
Case 3:
000 000 000
010 100 001
100 001 010
010 100 001
100 001 010
000 000 000
100 001 010
000 000 000
010 100 001
Case 4:
000 000 000
100 001 010
100 001 010
100 001 010
100 001 010
000 000 000
100 001 010
000 000 000
100 001 010
*/
const vector<int> dx = {0, 1, 1, 1};
const vector<int> dy = {1, 0, 1, 2};
for (int d = 0; d < 4; d++) {
if ((a.first + dx[d]) % 3 == b.first &&
(a.second + dy[d]) % 3 == b.second) {
return a;
}
}
return b;
}
} // namespace
void Anna(int N, int K, vector<int> R, vector<int> C) {
// Solution:
// We mark a node (x, y), where x mod 3 = 0 and y mod 3 = 0 with
// color L. Then, for Bruno, when we look at the 9 viewable cells,
// we know which one has x mod 3 = 0 and y mod 3 = 0.
//
// After that, we can identify each cell having 1 of 9 equivalence
// classes. The i-th class will hold information about the i-th goal.
// For the i-th goal, we only need to keep track of 13 possible information:
// 9, if the goal is close (9-adjacent to the cell of the class), and 4
// if the goal is far away. This yield 13 (for goal information) + 1 (to
// determine which cell has class x mod 3 = 0 and y mod 3 = 0).
//
// Since there are only 7 goals, there are only 7 possible values for the
// case when the goal is close. We color the other 2 values with L, and,
// while more difficult, we can still determine the 9 class of each cell.
// With this, we only need 7 (goal is near) + 4 (goal is fat) + 1 (special
// color L) = 12 colors.
vector<vector<int>> has_goal(3, vector<int>(3));
for (int i = 0; i < K; i++) {
has_goal[R[i] % 3][C[i] % 3] = 1;
}
vector<pair<int, int>> no_goals;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (!has_goal[i][j]) {
no_goals.emplace_back(i, j);
}
}
}
assert(no_goals.size() >= 2);
no_goals.resize(2);
vector<vector<int>> goal(3, vector<int>(3, -1));
auto zero = GetSpecial(no_goals[0], no_goals[1]);
for (int i = 0, cnt = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int x = (zero.first + i) % 3;
int y = (zero.second + j) % 3;
if (pair(x, y) != no_goals[0] && pair(x, y) != no_goals[1]) {
goal[i][j] = cnt++;
}
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
int g = goal[(i + 3 - zero.first) % 3][(j + 3 - zero.second) % 3];
if (g == -1) {
assert(!has_goal[i % 3][j % 3]);
SetFlag(i, j, 12);
} else {
int close = -1;
for (int di = -1; di <= 1; di++) {
for (int dj = -1; dj <= 1; dj++) {
if (R[g] == i + di && C[g] == j + dj) { // goal is close
assert(close == -1);
assert(goal[(R[g] + 3 - zero.first) % 3][(C[g] + 3 - zero.second) % 3] != -1);
close = goal[(R[g] + 3 - zero.first) % 3][(C[g] + 3 - zero.second) % 3] + 1;
}
}
}
if (close != -1) {
assert(1 <= close && close <= 7);
SetFlag(i, j, close);
} else {
if (i + 1 < R[g]) {
SetFlag(i, j, 8);
} else if (i - 1 > R[g]) {
SetFlag(i, j, 9);
} else if (j + 1 < C[g]) {
SetFlag(i, j, 10);
} else if (j - 1 > C[g]) {
SetFlag(i, j, 11);
} else {
assert(false);
}
}
}
}
}
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
pair<int, int> GetSpecial(pair<int, int> a, pair<int, int> b) {
/* List of classes determined by 2 special colors
Case 1:
000 000 000
000 000 000
110 101 011
000 000 000
110 101 011
000 000 000
110 101 011
000 000 000
000 000 000
Case 2:
000 000 000
001 010 100
100 001 010
001 010 100
100 001 010
000 000 000
100 001 010
000 000 000
001 010 100
Case 3:
000 000 000
010 100 001
100 001 010
010 100 001
100 001 010
000 000 000
100 001 010
000 000 000
010 100 001
Case 4:
000 000 000
100 001 010
100 001 010
100 001 010
100 001 010
000 000 000
100 001 010
000 000 000
100 001 010
*/
const vector<int> dx = {0, 1, 1, 1};
const vector<int> dy = {1, 0, 1, 2};
for (int d = 0; d < 4; d++) {
if ((a.first + dx[d]) % 3 == b.first &&
(a.second + dy[d]) % 3 == b.second) {
return a;
}
}
return b;
}
} // namespace
vector<int> Bruno(int K, vector<int> value) {
vector<int> res(K, -1);
vector<pair<int, int>> no_goals;
vector<vector<int>> values(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
values[i][j] = value[i * 3 + j];
if (values[i][j] == 12) {
no_goals.emplace_back(i, j);
}
}
}
assert(no_goals.size() == 2);
vector<vector<int>> goal(3, vector<int>(3, -1));
auto zero = GetSpecial(no_goals[0], no_goals[1]);
for (int i = 0, cnt = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int x = (zero.first + i) % 3;
int y = (zero.second + j) % 3;
if (pair(x, y) != no_goals[0] && pair(x, y) != no_goals[1]) {
goal[i][j] = cnt++;
}
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
int g = goal[(i + 3 - zero.first) % 3][(j + 3 - zero.second) % 3];
int close = values[i][j];
if (close == 12) {
assert(g == -1);
continue;
}
assert(g != -1);
// g-th goal has clue "close"
if (1 <= close && close <= 7) {
int Rg = -100, Cg = -100;
for (int di = -1; di <= 1; di++) {
for (int dj = -1; dj <= 1; dj++) {
if (goal[(i + di + 6 - zero.first) % 3][(j + dj + 6 - zero.second) % 3] + 1 == close) {
assert(Rg == -100 && Cg == -100);
Rg = i + di;
Cg = j + dj;
}
}
}
const auto Move = [&](int sr, int sc, int er, int ec) {
if (sr < er) {
return 2;
} else if (sr > er) {
return 3;
} else if (sc < ec) {
return 0;
} else if (sc > ec) {
return 1;
} else {
return 4;
}
};
res[g] = Move(1, 1, Rg, Cg);
} else {
if (close == 8) {
res[g] = 2;
} else if (close == 9) {
res[g] = 3;
} else if (close == 10) {
res[g] = 0;
} else if (close == 11) {
res[g] = 1;
}
}
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
448 KB |
Output is correct |
2 |
Correct |
10 ms |
468 KB |
Output is correct |
3 |
Correct |
10 ms |
476 KB |
Output is correct |
4 |
Correct |
18 ms |
388 KB |
Output is correct |
5 |
Correct |
15 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
472 KB |
Output is correct |
7 |
Correct |
16 ms |
384 KB |
Output is correct |
8 |
Correct |
23 ms |
388 KB |
Output is correct |
9 |
Correct |
15 ms |
392 KB |
Output is correct |
10 |
Correct |
16 ms |
388 KB |
Output is correct |
11 |
Correct |
15 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
384 KB |
Output is correct |
13 |
Correct |
11 ms |
472 KB |
Output is correct |
14 |
Correct |
15 ms |
384 KB |
Output is correct |
15 |
Correct |
19 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
384 KB |
Output is correct |
17 |
Correct |
11 ms |
560 KB |
Output is correct |
18 |
Correct |
14 ms |
388 KB |
Output is correct |
19 |
Correct |
15 ms |
384 KB |
Output is correct |
20 |
Correct |
14 ms |
468 KB |
Output is correct |
21 |
Correct |
11 ms |
384 KB |
Output is correct |
22 |
Correct |
11 ms |
472 KB |
Output is correct |
23 |
Correct |
17 ms |
384 KB |
Output is correct |
24 |
Correct |
17 ms |
388 KB |
Output is correct |
25 |
Correct |
16 ms |
384 KB |
Output is correct |
26 |
Correct |
15 ms |
384 KB |
Output is correct |
27 |
Correct |
14 ms |
384 KB |
Output is correct |
28 |
Correct |
12 ms |
384 KB |
Output is correct |
29 |
Correct |
16 ms |
388 KB |
Output is correct |
30 |
Correct |
12 ms |
384 KB |
Output is correct |
31 |
Correct |
19 ms |
388 KB |
Output is correct |
32 |
Correct |
16 ms |
472 KB |
Output is correct |
33 |
Correct |
16 ms |
384 KB |
Output is correct |
34 |
Correct |
13 ms |
384 KB |
Output is correct |
35 |
Correct |
18 ms |
384 KB |
Output is correct |
36 |
Correct |
17 ms |
388 KB |
Output is correct |
37 |
Correct |
20 ms |
384 KB |
Output is correct |
38 |
Correct |
18 ms |
384 KB |
Output is correct |
39 |
Correct |
20 ms |
384 KB |
Output is correct |
40 |
Correct |
19 ms |
384 KB |
Output is correct |
41 |
Correct |
19 ms |
420 KB |
Output is correct |
42 |
Correct |
19 ms |
384 KB |
Output is correct |
43 |
Correct |
16 ms |
384 KB |
Output is correct |
44 |
Correct |
13 ms |
464 KB |
Output is correct |
45 |
Correct |
17 ms |
384 KB |
Output is correct |
46 |
Correct |
19 ms |
384 KB |
Output is correct |
47 |
Correct |
22 ms |
384 KB |
Output is correct |
48 |
Correct |
22 ms |
388 KB |
Output is correct |
49 |
Correct |
19 ms |
384 KB |
Output is correct |
50 |
Correct |
15 ms |
472 KB |
Output is correct |
51 |
Correct |
17 ms |
468 KB |
Output is correct |
52 |
Correct |
18 ms |
384 KB |
Output is correct |
53 |
Correct |
19 ms |
472 KB |
Output is correct |
54 |
Correct |
17 ms |
392 KB |
Output is correct |
55 |
Correct |
19 ms |
388 KB |
Output is correct |
56 |
Correct |
22 ms |
384 KB |
Output is correct |
57 |
Correct |
20 ms |
384 KB |
Output is correct |
58 |
Correct |
20 ms |
384 KB |
Output is correct |
59 |
Correct |
25 ms |
392 KB |
Output is correct |
60 |
Correct |
21 ms |
472 KB |
Output is correct |
61 |
Correct |
26 ms |
384 KB |
Output is correct |
62 |
Correct |
28 ms |
396 KB |
Output is correct |
63 |
Correct |
27 ms |
384 KB |
Output is correct |
64 |
Correct |
16 ms |
384 KB |
Output is correct |
65 |
Correct |
16 ms |
384 KB |
Output is correct |
66 |
Correct |
21 ms |
388 KB |
Output is correct |
67 |
Correct |
19 ms |
384 KB |
Output is correct |
68 |
Correct |
28 ms |
384 KB |
Output is correct |
69 |
Correct |
18 ms |
448 KB |
Output is correct |
70 |
Correct |
25 ms |
472 KB |
Output is correct |
71 |
Correct |
16 ms |
384 KB |
Output is correct |
72 |
Correct |
24 ms |
384 KB |
Output is correct |
73 |
Correct |
17 ms |
468 KB |
Output is correct |
74 |
Correct |
22 ms |
384 KB |
Output is correct |
75 |
Correct |
27 ms |
384 KB |
Output is correct |
76 |
Correct |
28 ms |
388 KB |
Output is correct |
77 |
Correct |
20 ms |
388 KB |
Output is correct |
78 |
Correct |
29 ms |
384 KB |
Output is correct |
79 |
Correct |
30 ms |
388 KB |
Output is correct |
80 |
Correct |
23 ms |
388 KB |
Output is correct |
81 |
Correct |
28 ms |
388 KB |
Output is correct |
82 |
Correct |
21 ms |
388 KB |
Output is correct |
83 |
Correct |
27 ms |
468 KB |
Output is correct |
84 |
Correct |
21 ms |
384 KB |
Output is correct |
85 |
Correct |
24 ms |
436 KB |
Output is correct |
86 |
Correct |
23 ms |
384 KB |
Output is correct |
87 |
Correct |
21 ms |
388 KB |
Output is correct |
88 |
Correct |
22 ms |
384 KB |
Output is correct |
89 |
Correct |
22 ms |
384 KB |
Output is correct |
90 |
Correct |
23 ms |
388 KB |
Output is correct |
91 |
Correct |
16 ms |
388 KB |
Output is correct |
92 |
Correct |
25 ms |
388 KB |
Output is correct |
93 |
Correct |
24 ms |
384 KB |
Output is correct |
94 |
Correct |
18 ms |
384 KB |
Output is correct |
95 |
Correct |
27 ms |
384 KB |
Output is correct |
96 |
Correct |
27 ms |
388 KB |
Output is correct |
97 |
Correct |
20 ms |
384 KB |
Output is correct |
98 |
Correct |
27 ms |
384 KB |
Output is correct |
99 |
Correct |
21 ms |
384 KB |
Output is correct |
100 |
Correct |
26 ms |
384 KB |
Output is correct |
101 |
Correct |
29 ms |
384 KB |
Output is correct |
102 |
Correct |
22 ms |
384 KB |
Output is correct |
103 |
Correct |
20 ms |
384 KB |
Output is correct |
104 |
Correct |
24 ms |
384 KB |
Output is correct |
105 |
Correct |
22 ms |
384 KB |
Output is correct |
106 |
Correct |
20 ms |
384 KB |
Output is correct |
107 |
Correct |
22 ms |
384 KB |
Output is correct |
108 |
Correct |
26 ms |
528 KB |
Output is correct |
109 |
Correct |
22 ms |
384 KB |
Output is correct |
110 |
Correct |
20 ms |
384 KB |
Output is correct |
111 |
Correct |
20 ms |
388 KB |
Output is correct |
112 |
Correct |
15 ms |
560 KB |
Output is correct |
113 |
Correct |
20 ms |
388 KB |
Output is correct |
114 |
Correct |
20 ms |
472 KB |
Output is correct |
115 |
Correct |
23 ms |
384 KB |
Output is correct |
116 |
Correct |
20 ms |
384 KB |
Output is correct |
117 |
Correct |
16 ms |
384 KB |
Output is correct |
118 |
Correct |
22 ms |
384 KB |
Output is correct |
119 |
Correct |
19 ms |
384 KB |
Output is correct |
120 |
Correct |
823 ms |
688 KB |
Output is correct |
121 |
Correct |
774 ms |
600 KB |
Output is correct |
122 |
Correct |
775 ms |
760 KB |
Output is correct |
123 |
Correct |
901 ms |
572 KB |
Output is correct |
124 |
Correct |
806 ms |
604 KB |
Output is correct |
125 |
Correct |
832 ms |
600 KB |
Output is correct |
126 |
Correct |
784 ms |
512 KB |
Output is correct |
127 |
Correct |
838 ms |
576 KB |
Output is correct |
128 |
Correct |
754 ms |
488 KB |
Output is correct |
129 |
Correct |
886 ms |
580 KB |
Output is correct |
130 |
Correct |
765 ms |
760 KB |
Output is correct |
131 |
Correct |
817 ms |
548 KB |
Output is correct |
132 |
Correct |
816 ms |
744 KB |
Output is correct |
133 |
Correct |
867 ms |
564 KB |
Output is correct |
134 |
Correct |
759 ms |
604 KB |
Output is correct |
135 |
Correct |
930 ms |
568 KB |
Output is correct |
136 |
Correct |
791 ms |
524 KB |
Output is correct |
137 |
Correct |
864 ms |
492 KB |
Output is correct |
138 |
Correct |
878 ms |
512 KB |
Output is correct |
139 |
Correct |
796 ms |
488 KB |
Output is correct |
140 |
Correct |
765 ms |
512 KB |
Output is correct |
141 |
Correct |
813 ms |
576 KB |
Output is correct |
142 |
Correct |
833 ms |
508 KB |
Output is correct |
143 |
Correct |
781 ms |
496 KB |
Output is correct |
144 |
Correct |
894 ms |
516 KB |
Output is correct |
145 |
Correct |
921 ms |
660 KB |
Output is correct |
146 |
Correct |
938 ms |
488 KB |
Output is correct |
147 |
Correct |
778 ms |
560 KB |
Output is correct |
148 |
Correct |
787 ms |
612 KB |
Output is correct |
149 |
Correct |
780 ms |
572 KB |
Output is correct |
150 |
Correct |
766 ms |
584 KB |
Output is correct |
151 |
Correct |
896 ms |
492 KB |
Output is correct |
152 |
Correct |
990 ms |
496 KB |
Output is correct |
153 |
Correct |
810 ms |
588 KB |
Output is correct |
154 |
Correct |
826 ms |
620 KB |
Output is correct |
155 |
Correct |
886 ms |
748 KB |
Output is correct |
156 |
Correct |
794 ms |
664 KB |
Output is correct |
157 |
Correct |
853 ms |
696 KB |
Output is correct |
158 |
Correct |
839 ms |
572 KB |
Output is correct |
159 |
Correct |
777 ms |
624 KB |
Output is correct |
160 |
Correct |
770 ms |
556 KB |
Output is correct |
161 |
Correct |
805 ms |
628 KB |
Output is correct |
162 |
Correct |
751 ms |
488 KB |
Output is correct |
163 |
Correct |
827 ms |
556 KB |
Output is correct |
164 |
Correct |
809 ms |
716 KB |
Output is correct |
165 |
Correct |
815 ms |
780 KB |
Output is correct |
166 |
Correct |
766 ms |
672 KB |
Output is correct |
167 |
Correct |
795 ms |
612 KB |
Output is correct |
168 |
Correct |
851 ms |
600 KB |
Output is correct |
169 |
Correct |
799 ms |
492 KB |
Output is correct |
170 |
Correct |
826 ms |
684 KB |
Output is correct |
171 |
Correct |
766 ms |
656 KB |
Output is correct |
172 |
Correct |
747 ms |
684 KB |
Output is correct |
173 |
Correct |
809 ms |
864 KB |
Output is correct |
174 |
Correct |
756 ms |
892 KB |
Output is correct |
175 |
Correct |
781 ms |
604 KB |
Output is correct |
176 |
Correct |
799 ms |
592 KB |
Output is correct |
177 |
Correct |
820 ms |
584 KB |
Output is correct |
178 |
Correct |
776 ms |
568 KB |
Output is correct |
179 |
Correct |
795 ms |
760 KB |
Output is correct |
180 |
Correct |
832 ms |
628 KB |
Output is correct |
181 |
Correct |
835 ms |
764 KB |
Output is correct |
182 |
Correct |
792 ms |
736 KB |
Output is correct |
183 |
Correct |
822 ms |
740 KB |
Output is correct |
184 |
Correct |
783 ms |
628 KB |
Output is correct |
185 |
Correct |
784 ms |
648 KB |
Output is correct |
186 |
Correct |
756 ms |
888 KB |
Output is correct |
187 |
Correct |
874 ms |
588 KB |
Output is correct |
188 |
Correct |
770 ms |
564 KB |
Output is correct |
189 |
Correct |
841 ms |
720 KB |
Output is correct |
190 |
Correct |
803 ms |
612 KB |
Output is correct |
191 |
Correct |
843 ms |
664 KB |
Output is correct |
192 |
Correct |
760 ms |
624 KB |
Output is correct |
193 |
Correct |
816 ms |
788 KB |
Output is correct |
194 |
Correct |
929 ms |
728 KB |
Output is correct |
195 |
Correct |
805 ms |
580 KB |
Output is correct |
196 |
Correct |
750 ms |
732 KB |
Output is correct |
197 |
Correct |
767 ms |
568 KB |
Output is correct |
198 |
Correct |
777 ms |
592 KB |
Output is correct |
199 |
Correct |
782 ms |
724 KB |
Output is correct |
200 |
Correct |
766 ms |
512 KB |
Output is correct |
201 |
Correct |
845 ms |
644 KB |
Output is correct |
202 |
Correct |
810 ms |
648 KB |
Output is correct |
203 |
Correct |
836 ms |
572 KB |
Output is correct |
204 |
Correct |
827 ms |
632 KB |
Output is correct |
205 |
Correct |
886 ms |
528 KB |
Output is correct |
206 |
Correct |
866 ms |
680 KB |
Output is correct |
207 |
Correct |
912 ms |
504 KB |
Output is correct |
208 |
Correct |
898 ms |
724 KB |
Output is correct |
209 |
Correct |
920 ms |
652 KB |
Output is correct |
210 |
Correct |
735 ms |
576 KB |
Output is correct |
211 |
Correct |
602 ms |
512 KB |
Output is correct |
212 |
Correct |
738 ms |
492 KB |
Output is correct |
213 |
Correct |
695 ms |
588 KB |
Output is correct |
214 |
Correct |
679 ms |
488 KB |
Output is correct |
215 |
Correct |
672 ms |
528 KB |
Output is correct |
216 |
Correct |
680 ms |
488 KB |
Output is correct |
217 |
Correct |
595 ms |
496 KB |
Output is correct |
218 |
Correct |
623 ms |
640 KB |
Output is correct |
219 |
Correct |
766 ms |
496 KB |
Output is correct |
220 |
Correct |
595 ms |
556 KB |
Output is correct |
221 |
Correct |
635 ms |
596 KB |
Output is correct |
222 |
Correct |
748 ms |
540 KB |
Output is correct |
223 |
Correct |
670 ms |
736 KB |
Output is correct |
224 |
Correct |
628 ms |
768 KB |
Output is correct |
225 |
Correct |
654 ms |
820 KB |
Output is correct |
226 |
Correct |
586 ms |
668 KB |
Output is correct |