#include "Anna.h"
#include <cassert>
#include <cstring>
#include <vector>
using namespace std;
typedef vector<int> vi;
namespace A {
int hh[4][3][3] = {
{ { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 } },
{ { 0, 1, 2 }, { 7, 4, 5 }, { 6, 3, 8 } },
{ { 0, 1, 2 }, { 3, 7, 5 }, { 6, 4, 8 } },
{ { 0, 1, 2 }, { 3, 4, 7 }, { 6, 5, 8 } },
};
int dd[4] = { 3, 0, 1, 2 };
char bad[3][3];
}
void Anna(int n, int k, vi ii, vi jj) {
int g, i_, j_, d_, di_, dj_;
for (g = 0; g < 4; g++) {
d_ = A::dd[g], di_ = d_ / 3 - 1, dj_ = d_ % 3 - 1;
memset(A::bad, 0, sizeof A::bad);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
int h = A::hh[g][i][j];
if (h >= k)
continue;
A::bad[(i - ii[h] % 3 + 3) % 3][(j - jj[h] % 3 + 3) % 3] = 1;
A::bad[(i - (ii[h] + di_) % 3 + 3) % 3][(j - (jj[h] + dj_) % 3 + 3) % 3] = 1;
}
for (i_ = 0; i_ < 3; i_++)
for (j_ = 0; j_ < 3; j_++)
if (!A::bad[i_][j_])
goto out;
}
out:
assert(g < 4);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
int h = A::hh[g][(i + i_) % 3][(j + j_) % 3];
if (h >= k) {
SetFlag(i, j, 1);
continue;
}
int di = i - ii[h], dj = j - jj[h];
if (di < -1)
SetFlag(i, j, 2);
else if (di > 1)
SetFlag(i, j, 3);
else if (dj < -1)
SetFlag(i, j, 4);
else if (dj > 1)
SetFlag(i, j, 5);
else {
int d = (di + 1) * 3 + (dj + 1);
assert(d != d_ && d != 4);
if (d > 4)
d--;
if (d > d_)
d--;
SetFlag(i, j, 6 + d);
}
}
}
#include "Bruno.h"
#include <vector>
using namespace std;
typedef vector<int> vi;
namespace B {
int hh[4][3][3] = {
{ { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 } },
{ { 0, 1, 2 }, { 7, 4, 5 }, { 6, 3, 8 } },
{ { 0, 1, 2 }, { 3, 7, 5 }, { 6, 4, 8 } },
{ { 0, 1, 2 }, { 3, 4, 7 }, { 6, 5, 8 } },
};
int dd[4] = { 3, 0, 1, 2 };
int aa[3][3];
}
vi Bruno(int k, vi aa_) {
for (int ij = 0; ij < 9; ij++)
B::aa[ij / 3][ij % 3] = aa_[ij];
int g, d_, i_, j_;
for (g = 0; g < 4; g++) {
d_ = B::dd[g];
for (i_ = 0; i_ < 3; i_++)
for (j_ = 0; j_ < 3; j_++) {
int good = 1;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
if ((B::aa[(i + i_) % 3][(j + j_) % 3] == 1) != (B::hh[g][i][j] >= k)) {
good = 0;
goto out1;
}
out1:
if (good)
goto out2;
}
}
out2:
vi dir(k, 0);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
int h = B::hh[g][i][j];
if (h >= k)
continue;
int a = B::aa[(i + i_) % 3][(j + j_) % 3];
if (a == 2)
dir[h] = 2;
else if (a == 3)
dir[h] = 3;
else if (a == 4)
dir[h] = 0;
else if (a == 5)
dir[h] = 1;
else {
a -= 6;
if (a >= d_)
a++;
if (a >= 4)
a++;
int di = a / 3 - (i + i_) % 3, dj = a % 3 - (j + j_) % 3;
if (di < 0)
dir[h] = 2;
else if (di > 0)
dir[h] = 3;
else if (dj < 0)
dir[h] = 0;
else if (dj > 0)
dir[h] = 1;
else
dir[h] = 4;
}
}
return dir;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
400 KB |
Output is correct |
2 |
Correct |
17 ms |
400 KB |
Output is correct |
3 |
Correct |
13 ms |
516 KB |
Output is correct |
4 |
Correct |
12 ms |
400 KB |
Output is correct |
5 |
Correct |
11 ms |
400 KB |
Output is correct |
6 |
Correct |
11 ms |
472 KB |
Output is correct |
7 |
Correct |
10 ms |
400 KB |
Output is correct |
8 |
Correct |
15 ms |
400 KB |
Output is correct |
9 |
Correct |
13 ms |
400 KB |
Output is correct |
10 |
Correct |
14 ms |
400 KB |
Output is correct |
11 |
Correct |
15 ms |
400 KB |
Output is correct |
12 |
Correct |
10 ms |
400 KB |
Output is correct |
13 |
Correct |
12 ms |
400 KB |
Output is correct |
14 |
Correct |
13 ms |
400 KB |
Output is correct |
15 |
Correct |
12 ms |
472 KB |
Output is correct |
16 |
Correct |
14 ms |
400 KB |
Output is correct |
17 |
Correct |
12 ms |
400 KB |
Output is correct |
18 |
Correct |
13 ms |
400 KB |
Output is correct |
19 |
Correct |
13 ms |
400 KB |
Output is correct |
20 |
Correct |
12 ms |
400 KB |
Output is correct |
21 |
Correct |
15 ms |
400 KB |
Output is correct |
22 |
Correct |
15 ms |
400 KB |
Output is correct |
23 |
Correct |
12 ms |
400 KB |
Output is correct |
24 |
Correct |
14 ms |
400 KB |
Output is correct |
25 |
Correct |
15 ms |
400 KB |
Output is correct |
26 |
Correct |
15 ms |
400 KB |
Output is correct |
27 |
Correct |
14 ms |
400 KB |
Output is correct |
28 |
Correct |
11 ms |
400 KB |
Output is correct |
29 |
Correct |
16 ms |
400 KB |
Output is correct |
30 |
Correct |
15 ms |
400 KB |
Output is correct |
31 |
Correct |
17 ms |
400 KB |
Output is correct |
32 |
Correct |
11 ms |
400 KB |
Output is correct |
33 |
Correct |
14 ms |
400 KB |
Output is correct |
34 |
Correct |
14 ms |
400 KB |
Output is correct |
35 |
Correct |
12 ms |
456 KB |
Output is correct |
36 |
Correct |
13 ms |
400 KB |
Output is correct |
37 |
Correct |
13 ms |
400 KB |
Output is correct |
38 |
Correct |
17 ms |
400 KB |
Output is correct |
39 |
Correct |
14 ms |
400 KB |
Output is correct |
40 |
Correct |
11 ms |
468 KB |
Output is correct |
41 |
Correct |
16 ms |
400 KB |
Output is correct |
42 |
Correct |
14 ms |
400 KB |
Output is correct |
43 |
Correct |
16 ms |
400 KB |
Output is correct |
44 |
Correct |
17 ms |
400 KB |
Output is correct |
45 |
Correct |
12 ms |
400 KB |
Output is correct |
46 |
Correct |
15 ms |
400 KB |
Output is correct |
47 |
Correct |
13 ms |
400 KB |
Output is correct |
48 |
Correct |
17 ms |
400 KB |
Output is correct |
49 |
Correct |
16 ms |
420 KB |
Output is correct |
50 |
Correct |
17 ms |
424 KB |
Output is correct |
51 |
Correct |
18 ms |
424 KB |
Output is correct |
52 |
Correct |
16 ms |
424 KB |
Output is correct |
53 |
Correct |
16 ms |
424 KB |
Output is correct |
54 |
Correct |
15 ms |
424 KB |
Output is correct |
55 |
Correct |
14 ms |
424 KB |
Output is correct |
56 |
Correct |
18 ms |
424 KB |
Output is correct |
57 |
Correct |
17 ms |
420 KB |
Output is correct |
58 |
Correct |
15 ms |
400 KB |
Output is correct |
59 |
Correct |
17 ms |
400 KB |
Output is correct |
60 |
Correct |
20 ms |
400 KB |
Output is correct |
61 |
Correct |
16 ms |
400 KB |
Output is correct |
62 |
Correct |
17 ms |
400 KB |
Output is correct |
63 |
Correct |
15 ms |
472 KB |
Output is correct |
64 |
Correct |
21 ms |
528 KB |
Output is correct |
65 |
Correct |
13 ms |
400 KB |
Output is correct |
66 |
Correct |
16 ms |
400 KB |
Output is correct |
67 |
Correct |
19 ms |
400 KB |
Output is correct |
68 |
Correct |
17 ms |
400 KB |
Output is correct |
69 |
Correct |
15 ms |
472 KB |
Output is correct |
70 |
Correct |
17 ms |
400 KB |
Output is correct |
71 |
Correct |
15 ms |
400 KB |
Output is correct |
72 |
Correct |
17 ms |
400 KB |
Output is correct |
73 |
Correct |
17 ms |
476 KB |
Output is correct |
74 |
Correct |
19 ms |
400 KB |
Output is correct |
75 |
Correct |
20 ms |
400 KB |
Output is correct |
76 |
Correct |
21 ms |
400 KB |
Output is correct |
77 |
Correct |
19 ms |
400 KB |
Output is correct |
78 |
Correct |
15 ms |
400 KB |
Output is correct |
79 |
Correct |
17 ms |
400 KB |
Output is correct |
80 |
Correct |
19 ms |
400 KB |
Output is correct |
81 |
Correct |
14 ms |
400 KB |
Output is correct |
82 |
Correct |
16 ms |
404 KB |
Output is correct |
83 |
Correct |
19 ms |
424 KB |
Output is correct |
84 |
Correct |
18 ms |
496 KB |
Output is correct |
85 |
Correct |
20 ms |
424 KB |
Output is correct |
86 |
Correct |
14 ms |
424 KB |
Output is correct |
87 |
Correct |
13 ms |
424 KB |
Output is correct |
88 |
Correct |
18 ms |
424 KB |
Output is correct |
89 |
Correct |
16 ms |
424 KB |
Output is correct |
90 |
Correct |
20 ms |
496 KB |
Output is correct |
91 |
Correct |
21 ms |
420 KB |
Output is correct |
92 |
Correct |
15 ms |
424 KB |
Output is correct |
93 |
Correct |
21 ms |
404 KB |
Output is correct |
94 |
Correct |
16 ms |
472 KB |
Output is correct |
95 |
Correct |
22 ms |
400 KB |
Output is correct |
96 |
Correct |
20 ms |
400 KB |
Output is correct |
97 |
Correct |
18 ms |
468 KB |
Output is correct |
98 |
Correct |
17 ms |
472 KB |
Output is correct |
99 |
Correct |
15 ms |
400 KB |
Output is correct |
100 |
Correct |
19 ms |
400 KB |
Output is correct |
101 |
Correct |
20 ms |
400 KB |
Output is correct |
102 |
Correct |
20 ms |
400 KB |
Output is correct |
103 |
Correct |
18 ms |
456 KB |
Output is correct |
104 |
Correct |
15 ms |
468 KB |
Output is correct |
105 |
Correct |
16 ms |
400 KB |
Output is correct |
106 |
Correct |
19 ms |
400 KB |
Output is correct |
107 |
Correct |
18 ms |
400 KB |
Output is correct |
108 |
Correct |
16 ms |
400 KB |
Output is correct |
109 |
Correct |
15 ms |
400 KB |
Output is correct |
110 |
Correct |
15 ms |
400 KB |
Output is correct |
111 |
Correct |
16 ms |
400 KB |
Output is correct |
112 |
Correct |
14 ms |
400 KB |
Output is correct |
113 |
Correct |
21 ms |
400 KB |
Output is correct |
114 |
Correct |
19 ms |
400 KB |
Output is correct |
115 |
Correct |
21 ms |
400 KB |
Output is correct |
116 |
Correct |
18 ms |
400 KB |
Output is correct |
117 |
Correct |
18 ms |
400 KB |
Output is correct |
118 |
Correct |
16 ms |
400 KB |
Output is correct |
119 |
Correct |
15 ms |
400 KB |
Output is correct |
120 |
Correct |
628 ms |
624 KB |
Output is correct |
121 |
Correct |
707 ms |
612 KB |
Output is correct |
122 |
Correct |
655 ms |
636 KB |
Output is correct |
123 |
Correct |
795 ms |
568 KB |
Output is correct |
124 |
Correct |
660 ms |
668 KB |
Output is correct |
125 |
Correct |
715 ms |
584 KB |
Output is correct |
126 |
Correct |
752 ms |
624 KB |
Output is correct |
127 |
Correct |
719 ms |
672 KB |
Output is correct |
128 |
Correct |
684 ms |
616 KB |
Output is correct |
129 |
Correct |
637 ms |
684 KB |
Output is correct |
130 |
Correct |
655 ms |
684 KB |
Output is correct |
131 |
Correct |
636 ms |
524 KB |
Output is correct |
132 |
Correct |
624 ms |
676 KB |
Output is correct |
133 |
Correct |
638 ms |
692 KB |
Output is correct |
134 |
Correct |
666 ms |
720 KB |
Output is correct |
135 |
Correct |
605 ms |
776 KB |
Output is correct |
136 |
Correct |
572 ms |
684 KB |
Output is correct |
137 |
Correct |
581 ms |
580 KB |
Output is correct |
138 |
Correct |
618 ms |
736 KB |
Output is correct |
139 |
Correct |
573 ms |
592 KB |
Output is correct |
140 |
Correct |
636 ms |
596 KB |
Output is correct |
141 |
Correct |
638 ms |
800 KB |
Output is correct |
142 |
Correct |
610 ms |
616 KB |
Output is correct |
143 |
Correct |
679 ms |
696 KB |
Output is correct |
144 |
Correct |
756 ms |
652 KB |
Output is correct |
145 |
Correct |
813 ms |
560 KB |
Output is correct |
146 |
Correct |
693 ms |
556 KB |
Output is correct |
147 |
Correct |
770 ms |
584 KB |
Output is correct |
148 |
Correct |
609 ms |
592 KB |
Output is correct |
149 |
Correct |
682 ms |
668 KB |
Output is correct |
150 |
Correct |
681 ms |
740 KB |
Output is correct |
151 |
Correct |
721 ms |
684 KB |
Output is correct |
152 |
Correct |
719 ms |
644 KB |
Output is correct |
153 |
Correct |
598 ms |
656 KB |
Output is correct |
154 |
Correct |
620 ms |
684 KB |
Output is correct |
155 |
Correct |
573 ms |
616 KB |
Output is correct |
156 |
Correct |
580 ms |
696 KB |
Output is correct |
157 |
Correct |
602 ms |
672 KB |
Output is correct |
158 |
Correct |
590 ms |
764 KB |
Output is correct |
159 |
Correct |
634 ms |
656 KB |
Output is correct |
160 |
Correct |
592 ms |
644 KB |
Output is correct |
161 |
Correct |
602 ms |
648 KB |
Output is correct |
162 |
Correct |
572 ms |
648 KB |
Output is correct |
163 |
Correct |
610 ms |
628 KB |
Output is correct |
164 |
Correct |
633 ms |
752 KB |
Output is correct |
165 |
Correct |
622 ms |
604 KB |
Output is correct |
166 |
Correct |
667 ms |
548 KB |
Output is correct |
167 |
Correct |
591 ms |
644 KB |
Output is correct |
168 |
Correct |
594 ms |
676 KB |
Output is correct |
169 |
Correct |
583 ms |
688 KB |
Output is correct |
170 |
Correct |
622 ms |
632 KB |
Output is correct |
171 |
Correct |
650 ms |
600 KB |
Output is correct |
172 |
Correct |
631 ms |
580 KB |
Output is correct |
173 |
Correct |
630 ms |
704 KB |
Output is correct |
174 |
Correct |
630 ms |
620 KB |
Output is correct |
175 |
Correct |
640 ms |
672 KB |
Output is correct |
176 |
Correct |
653 ms |
716 KB |
Output is correct |
177 |
Correct |
669 ms |
776 KB |
Output is correct |
178 |
Correct |
723 ms |
604 KB |
Output is correct |
179 |
Correct |
595 ms |
812 KB |
Output is correct |
180 |
Correct |
630 ms |
612 KB |
Output is correct |
181 |
Correct |
609 ms |
712 KB |
Output is correct |
182 |
Correct |
638 ms |
684 KB |
Output is correct |
183 |
Correct |
661 ms |
572 KB |
Output is correct |
184 |
Correct |
587 ms |
628 KB |
Output is correct |
185 |
Correct |
554 ms |
588 KB |
Output is correct |
186 |
Correct |
631 ms |
800 KB |
Output is correct |
187 |
Correct |
621 ms |
656 KB |
Output is correct |
188 |
Correct |
583 ms |
708 KB |
Output is correct |
189 |
Correct |
587 ms |
568 KB |
Output is correct |
190 |
Correct |
644 ms |
600 KB |
Output is correct |
191 |
Correct |
715 ms |
764 KB |
Output is correct |
192 |
Correct |
653 ms |
584 KB |
Output is correct |
193 |
Correct |
626 ms |
696 KB |
Output is correct |
194 |
Correct |
614 ms |
692 KB |
Output is correct |
195 |
Correct |
702 ms |
708 KB |
Output is correct |
196 |
Correct |
633 ms |
576 KB |
Output is correct |
197 |
Correct |
691 ms |
596 KB |
Output is correct |
198 |
Correct |
637 ms |
788 KB |
Output is correct |
199 |
Correct |
635 ms |
640 KB |
Output is correct |
200 |
Correct |
596 ms |
668 KB |
Output is correct |
201 |
Correct |
690 ms |
660 KB |
Output is correct |
202 |
Correct |
647 ms |
672 KB |
Output is correct |
203 |
Correct |
664 ms |
616 KB |
Output is correct |
204 |
Correct |
664 ms |
600 KB |
Output is correct |
205 |
Correct |
631 ms |
692 KB |
Output is correct |
206 |
Correct |
674 ms |
732 KB |
Output is correct |
207 |
Correct |
660 ms |
784 KB |
Output is correct |
208 |
Correct |
628 ms |
632 KB |
Output is correct |
209 |
Correct |
668 ms |
616 KB |
Output is correct |
210 |
Correct |
518 ms |
628 KB |
Output is correct |
211 |
Correct |
420 ms |
648 KB |
Output is correct |
212 |
Correct |
434 ms |
508 KB |
Output is correct |
213 |
Correct |
548 ms |
688 KB |
Output is correct |
214 |
Correct |
458 ms |
600 KB |
Output is correct |
215 |
Correct |
514 ms |
668 KB |
Output is correct |
216 |
Correct |
520 ms |
612 KB |
Output is correct |
217 |
Correct |
546 ms |
612 KB |
Output is correct |
218 |
Correct |
444 ms |
928 KB |
Output is correct |
219 |
Correct |
501 ms |
604 KB |
Output is correct |
220 |
Correct |
479 ms |
488 KB |
Output is correct |
221 |
Correct |
536 ms |
708 KB |
Output is correct |
222 |
Correct |
486 ms |
668 KB |
Output is correct |
223 |
Correct |
482 ms |
688 KB |
Output is correct |
224 |
Correct |
512 ms |
560 KB |
Output is correct |
225 |
Correct |
457 ms |
596 KB |
Output is correct |
226 |
Correct |
499 ms |
672 KB |
Output is correct |