#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
namespace {
const int dx[4] = {0, 1, 1, 1};
const int dy[4] = {1, -1, 0, 1};
pi extract_pattern(int A[3][3], int eq){
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if(A[i][j] == eq){
for(int k = 0; k < 4; k++){
if(A[(i + dx[k] + 3) % 3][(j + dy[k] + 3) % 3] == eq){
return pi(i, j);
}
}
}
}
}
assert(0);
}
} // namespace
void Anna(int N, int K, std::vector<int> R, std::vector<int> C) {
int chk[3][3] = {};
for(int i = 0; i < K; i++){
chk[R[i] % 3][C[i] % 3] = 1;
}
int cnt = 0;
int A[3][3] = {};
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if(!chk[i][j] && cnt < 2){
A[i][j] = 12;
cnt++;
}
}
}
int piv = 0;
pi center = extract_pattern(A, 12);
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if(!A[(center.first + i) % 3][(center.second + j) % 3]){
A[(center.first + i) % 3][(center.second + j) % 3] = ++piv;
}
}
}
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(A[i%3][j%3] == 12) SetFlag(i, j, 12);
else{
int to_seek = A[i%3][j%3] - 1;
if(to_seek >= K){
SetFlag(i, j, 11);
continue;
}
if(abs(R[to_seek] - i) >= 2 || abs(C[to_seek] - j) >= 2){
if(R[to_seek] >= i + 2) SetFlag(i, j, 3);
else if(R[to_seek] <= i - 2) SetFlag(i, j, 4);
else if(C[to_seek] >= j + 2) SetFlag(i, j, 1);
else if(C[to_seek] <= j - 2) SetFlag(i, j, 2);
else assert(0);
}
else{
SetFlag(i, j, 4 + A[R[to_seek] % 3][C[to_seek] % 3]);
}
}
}
}
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
namespace {
const int dx[4] = {0, 1, 1, 1};
const int dy[4] = {1, -1, 0, 1};
pi extract_pattern(int A[3][3], int eq){
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if(A[i][j] == eq){
for(int k = 0; k < 4; k++){
if(A[(i + dx[k] + 3) % 3][(j + dy[k] + 3) % 3] == eq){
return pi(i, j);
}
}
}
}
}
assert(0);
}
} // namespace
std::vector<int> Bruno(int K, std::vector<int> value) {
int A[3][3] = {};
int B[3][3] = {}, piv = 0;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
A[i][j] = value[i*3+j];
if(A[i][j] == 12) B[i][j] = 12;
}
}
pi center = extract_pattern(A, 12);
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if(!B[(center.first + i) % 3][(center.second + j) % 3]){
B[(center.first + i) % 3][(center.second + j) % 3] = ++piv;
}
}
}
vector<int> res;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
int v = A[(center.first + i) % 3][(center.second + j) % 3];
if(v == 12) continue;
if(sz(res) == K) continue;
if(v <= 4) res.push_back(v - 1);
else{
// printf("%d goes %d\n", sz(res), v - 4);
v -= 4;
// check perspective of where.
for(int k = 0; k < 3; k++){
for(int l = 0; l < 3; l++){
if(B[k][l] == v){
int new_x = (center.first + i) % 3;
int new_y = (center.second + j) % 3;
while((new_x + 369) % 3 != (k + 2) % 3) new_x--;
while((new_y + 369) % 3 != (l + 2) % 3) new_y--;
// printf("offset is %d %d\n", new_x, new_y);
if(new_x > 0) res.push_back(2);
else if(new_x < 0) res.push_back(3);
else if(new_y > 0) res.push_back(0);
else if(new_y < 0) res.push_back(1);
else res.push_back(4);
}
}
}
}
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
384 KB |
Output is correct |
2 |
Correct |
13 ms |
384 KB |
Output is correct |
3 |
Correct |
12 ms |
384 KB |
Output is correct |
4 |
Correct |
13 ms |
384 KB |
Output is correct |
5 |
Correct |
16 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
384 KB |
Output is correct |
7 |
Correct |
14 ms |
384 KB |
Output is correct |
8 |
Correct |
18 ms |
384 KB |
Output is correct |
9 |
Correct |
17 ms |
384 KB |
Output is correct |
10 |
Correct |
13 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
384 KB |
Output is correct |
12 |
Correct |
18 ms |
384 KB |
Output is correct |
13 |
Correct |
14 ms |
384 KB |
Output is correct |
14 |
Correct |
14 ms |
384 KB |
Output is correct |
15 |
Correct |
13 ms |
384 KB |
Output is correct |
16 |
Correct |
13 ms |
384 KB |
Output is correct |
17 |
Correct |
13 ms |
472 KB |
Output is correct |
18 |
Correct |
14 ms |
384 KB |
Output is correct |
19 |
Correct |
14 ms |
384 KB |
Output is correct |
20 |
Correct |
17 ms |
384 KB |
Output is correct |
21 |
Correct |
14 ms |
388 KB |
Output is correct |
22 |
Correct |
15 ms |
384 KB |
Output is correct |
23 |
Correct |
17 ms |
384 KB |
Output is correct |
24 |
Correct |
15 ms |
388 KB |
Output is correct |
25 |
Correct |
14 ms |
384 KB |
Output is correct |
26 |
Correct |
15 ms |
384 KB |
Output is correct |
27 |
Correct |
13 ms |
384 KB |
Output is correct |
28 |
Correct |
14 ms |
388 KB |
Output is correct |
29 |
Correct |
14 ms |
388 KB |
Output is correct |
30 |
Correct |
12 ms |
384 KB |
Output is correct |
31 |
Correct |
15 ms |
384 KB |
Output is correct |
32 |
Correct |
16 ms |
384 KB |
Output is correct |
33 |
Correct |
17 ms |
384 KB |
Output is correct |
34 |
Correct |
18 ms |
384 KB |
Output is correct |
35 |
Correct |
15 ms |
388 KB |
Output is correct |
36 |
Correct |
15 ms |
448 KB |
Output is correct |
37 |
Correct |
10 ms |
468 KB |
Output is correct |
38 |
Correct |
15 ms |
388 KB |
Output is correct |
39 |
Correct |
15 ms |
384 KB |
Output is correct |
40 |
Correct |
13 ms |
388 KB |
Output is correct |
41 |
Correct |
17 ms |
384 KB |
Output is correct |
42 |
Correct |
15 ms |
384 KB |
Output is correct |
43 |
Correct |
18 ms |
384 KB |
Output is correct |
44 |
Correct |
13 ms |
388 KB |
Output is correct |
45 |
Correct |
17 ms |
384 KB |
Output is correct |
46 |
Correct |
15 ms |
384 KB |
Output is correct |
47 |
Correct |
18 ms |
384 KB |
Output is correct |
48 |
Correct |
17 ms |
388 KB |
Output is correct |
49 |
Correct |
18 ms |
388 KB |
Output is correct |
50 |
Correct |
19 ms |
388 KB |
Output is correct |
51 |
Correct |
15 ms |
384 KB |
Output is correct |
52 |
Correct |
19 ms |
384 KB |
Output is correct |
53 |
Correct |
19 ms |
388 KB |
Output is correct |
54 |
Correct |
19 ms |
384 KB |
Output is correct |
55 |
Correct |
16 ms |
384 KB |
Output is correct |
56 |
Correct |
17 ms |
384 KB |
Output is correct |
57 |
Correct |
18 ms |
384 KB |
Output is correct |
58 |
Correct |
20 ms |
384 KB |
Output is correct |
59 |
Correct |
18 ms |
384 KB |
Output is correct |
60 |
Correct |
19 ms |
384 KB |
Output is correct |
61 |
Correct |
22 ms |
384 KB |
Output is correct |
62 |
Correct |
20 ms |
388 KB |
Output is correct |
63 |
Correct |
18 ms |
472 KB |
Output is correct |
64 |
Correct |
21 ms |
388 KB |
Output is correct |
65 |
Correct |
15 ms |
384 KB |
Output is correct |
66 |
Correct |
23 ms |
384 KB |
Output is correct |
67 |
Correct |
18 ms |
388 KB |
Output is correct |
68 |
Correct |
20 ms |
384 KB |
Output is correct |
69 |
Correct |
22 ms |
388 KB |
Output is correct |
70 |
Correct |
22 ms |
388 KB |
Output is correct |
71 |
Correct |
24 ms |
384 KB |
Output is correct |
72 |
Correct |
19 ms |
384 KB |
Output is correct |
73 |
Correct |
19 ms |
384 KB |
Output is correct |
74 |
Correct |
18 ms |
384 KB |
Output is correct |
75 |
Correct |
17 ms |
384 KB |
Output is correct |
76 |
Correct |
17 ms |
396 KB |
Output is correct |
77 |
Correct |
18 ms |
384 KB |
Output is correct |
78 |
Correct |
19 ms |
388 KB |
Output is correct |
79 |
Correct |
19 ms |
384 KB |
Output is correct |
80 |
Correct |
22 ms |
384 KB |
Output is correct |
81 |
Correct |
23 ms |
384 KB |
Output is correct |
82 |
Correct |
20 ms |
388 KB |
Output is correct |
83 |
Correct |
19 ms |
384 KB |
Output is correct |
84 |
Correct |
24 ms |
384 KB |
Output is correct |
85 |
Correct |
22 ms |
384 KB |
Output is correct |
86 |
Correct |
18 ms |
384 KB |
Output is correct |
87 |
Correct |
20 ms |
384 KB |
Output is correct |
88 |
Correct |
24 ms |
384 KB |
Output is correct |
89 |
Correct |
20 ms |
384 KB |
Output is correct |
90 |
Correct |
17 ms |
388 KB |
Output is correct |
91 |
Correct |
19 ms |
384 KB |
Output is correct |
92 |
Correct |
19 ms |
384 KB |
Output is correct |
93 |
Correct |
20 ms |
384 KB |
Output is correct |
94 |
Correct |
22 ms |
384 KB |
Output is correct |
95 |
Correct |
18 ms |
472 KB |
Output is correct |
96 |
Correct |
18 ms |
384 KB |
Output is correct |
97 |
Correct |
16 ms |
468 KB |
Output is correct |
98 |
Correct |
23 ms |
392 KB |
Output is correct |
99 |
Correct |
16 ms |
384 KB |
Output is correct |
100 |
Correct |
19 ms |
384 KB |
Output is correct |
101 |
Correct |
22 ms |
384 KB |
Output is correct |
102 |
Correct |
19 ms |
384 KB |
Output is correct |
103 |
Correct |
19 ms |
388 KB |
Output is correct |
104 |
Correct |
20 ms |
384 KB |
Output is correct |
105 |
Correct |
19 ms |
472 KB |
Output is correct |
106 |
Correct |
19 ms |
384 KB |
Output is correct |
107 |
Correct |
23 ms |
384 KB |
Output is correct |
108 |
Correct |
20 ms |
384 KB |
Output is correct |
109 |
Correct |
18 ms |
384 KB |
Output is correct |
110 |
Correct |
18 ms |
392 KB |
Output is correct |
111 |
Correct |
22 ms |
384 KB |
Output is correct |
112 |
Correct |
18 ms |
472 KB |
Output is correct |
113 |
Correct |
25 ms |
384 KB |
Output is correct |
114 |
Correct |
20 ms |
392 KB |
Output is correct |
115 |
Correct |
22 ms |
384 KB |
Output is correct |
116 |
Correct |
17 ms |
384 KB |
Output is correct |
117 |
Correct |
20 ms |
384 KB |
Output is correct |
118 |
Correct |
23 ms |
384 KB |
Output is correct |
119 |
Correct |
19 ms |
388 KB |
Output is correct |
120 |
Correct |
666 ms |
644 KB |
Output is correct |
121 |
Correct |
712 ms |
624 KB |
Output is correct |
122 |
Correct |
655 ms |
724 KB |
Output is correct |
123 |
Correct |
677 ms |
724 KB |
Output is correct |
124 |
Correct |
729 ms |
524 KB |
Output is correct |
125 |
Correct |
661 ms |
620 KB |
Output is correct |
126 |
Correct |
762 ms |
672 KB |
Output is correct |
127 |
Correct |
681 ms |
604 KB |
Output is correct |
128 |
Correct |
727 ms |
620 KB |
Output is correct |
129 |
Correct |
754 ms |
568 KB |
Output is correct |
130 |
Correct |
671 ms |
648 KB |
Output is correct |
131 |
Correct |
720 ms |
568 KB |
Output is correct |
132 |
Correct |
725 ms |
648 KB |
Output is correct |
133 |
Correct |
667 ms |
756 KB |
Output is correct |
134 |
Correct |
735 ms |
660 KB |
Output is correct |
135 |
Correct |
693 ms |
756 KB |
Output is correct |
136 |
Correct |
752 ms |
684 KB |
Output is correct |
137 |
Correct |
675 ms |
680 KB |
Output is correct |
138 |
Correct |
706 ms |
928 KB |
Output is correct |
139 |
Correct |
663 ms |
728 KB |
Output is correct |
140 |
Correct |
705 ms |
688 KB |
Output is correct |
141 |
Correct |
705 ms |
792 KB |
Output is correct |
142 |
Correct |
705 ms |
620 KB |
Output is correct |
143 |
Correct |
655 ms |
724 KB |
Output is correct |
144 |
Correct |
659 ms |
636 KB |
Output is correct |
145 |
Correct |
800 ms |
632 KB |
Output is correct |
146 |
Correct |
655 ms |
704 KB |
Output is correct |
147 |
Correct |
685 ms |
612 KB |
Output is correct |
148 |
Correct |
749 ms |
556 KB |
Output is correct |
149 |
Correct |
733 ms |
608 KB |
Output is correct |
150 |
Correct |
691 ms |
580 KB |
Output is correct |
151 |
Correct |
659 ms |
644 KB |
Output is correct |
152 |
Correct |
965 ms |
632 KB |
Output is correct |
153 |
Correct |
737 ms |
632 KB |
Output is correct |
154 |
Correct |
758 ms |
656 KB |
Output is correct |
155 |
Correct |
819 ms |
700 KB |
Output is correct |
156 |
Correct |
664 ms |
784 KB |
Output is correct |
157 |
Correct |
676 ms |
632 KB |
Output is correct |
158 |
Correct |
746 ms |
732 KB |
Output is correct |
159 |
Correct |
679 ms |
692 KB |
Output is correct |
160 |
Correct |
688 ms |
732 KB |
Output is correct |
161 |
Correct |
661 ms |
584 KB |
Output is correct |
162 |
Correct |
704 ms |
692 KB |
Output is correct |
163 |
Correct |
656 ms |
644 KB |
Output is correct |
164 |
Correct |
810 ms |
656 KB |
Output is correct |
165 |
Correct |
787 ms |
640 KB |
Output is correct |
166 |
Correct |
664 ms |
680 KB |
Output is correct |
167 |
Correct |
672 ms |
864 KB |
Output is correct |
168 |
Correct |
653 ms |
784 KB |
Output is correct |
169 |
Correct |
715 ms |
732 KB |
Output is correct |
170 |
Correct |
677 ms |
656 KB |
Output is correct |
171 |
Correct |
739 ms |
680 KB |
Output is correct |
172 |
Correct |
700 ms |
764 KB |
Output is correct |
173 |
Correct |
661 ms |
728 KB |
Output is correct |
174 |
Correct |
686 ms |
668 KB |
Output is correct |
175 |
Correct |
680 ms |
668 KB |
Output is correct |
176 |
Correct |
680 ms |
600 KB |
Output is correct |
177 |
Correct |
672 ms |
752 KB |
Output is correct |
178 |
Correct |
675 ms |
612 KB |
Output is correct |
179 |
Correct |
656 ms |
656 KB |
Output is correct |
180 |
Correct |
658 ms |
704 KB |
Output is correct |
181 |
Correct |
650 ms |
592 KB |
Output is correct |
182 |
Correct |
670 ms |
676 KB |
Output is correct |
183 |
Correct |
662 ms |
620 KB |
Output is correct |
184 |
Correct |
656 ms |
564 KB |
Output is correct |
185 |
Correct |
689 ms |
592 KB |
Output is correct |
186 |
Correct |
698 ms |
616 KB |
Output is correct |
187 |
Correct |
680 ms |
564 KB |
Output is correct |
188 |
Correct |
693 ms |
688 KB |
Output is correct |
189 |
Correct |
798 ms |
712 KB |
Output is correct |
190 |
Correct |
738 ms |
716 KB |
Output is correct |
191 |
Correct |
662 ms |
560 KB |
Output is correct |
192 |
Correct |
777 ms |
644 KB |
Output is correct |
193 |
Correct |
746 ms |
752 KB |
Output is correct |
194 |
Correct |
709 ms |
720 KB |
Output is correct |
195 |
Correct |
816 ms |
840 KB |
Output is correct |
196 |
Correct |
717 ms |
652 KB |
Output is correct |
197 |
Correct |
657 ms |
640 KB |
Output is correct |
198 |
Correct |
778 ms |
576 KB |
Output is correct |
199 |
Correct |
681 ms |
608 KB |
Output is correct |
200 |
Correct |
664 ms |
768 KB |
Output is correct |
201 |
Correct |
669 ms |
676 KB |
Output is correct |
202 |
Correct |
676 ms |
680 KB |
Output is correct |
203 |
Correct |
674 ms |
724 KB |
Output is correct |
204 |
Correct |
688 ms |
692 KB |
Output is correct |
205 |
Correct |
680 ms |
616 KB |
Output is correct |
206 |
Correct |
648 ms |
680 KB |
Output is correct |
207 |
Correct |
661 ms |
620 KB |
Output is correct |
208 |
Correct |
655 ms |
608 KB |
Output is correct |
209 |
Correct |
676 ms |
644 KB |
Output is correct |
210 |
Correct |
527 ms |
560 KB |
Output is correct |
211 |
Correct |
522 ms |
696 KB |
Output is correct |
212 |
Correct |
500 ms |
780 KB |
Output is correct |
213 |
Correct |
500 ms |
820 KB |
Output is correct |
214 |
Correct |
495 ms |
800 KB |
Output is correct |
215 |
Correct |
674 ms |
636 KB |
Output is correct |
216 |
Correct |
510 ms |
744 KB |
Output is correct |
217 |
Correct |
514 ms |
604 KB |
Output is correct |
218 |
Correct |
499 ms |
656 KB |
Output is correct |
219 |
Correct |
521 ms |
688 KB |
Output is correct |
220 |
Correct |
548 ms |
540 KB |
Output is correct |
221 |
Correct |
500 ms |
648 KB |
Output is correct |
222 |
Correct |
598 ms |
620 KB |
Output is correct |
223 |
Correct |
542 ms |
576 KB |
Output is correct |
224 |
Correct |
509 ms |
524 KB |
Output is correct |
225 |
Correct |
507 ms |
744 KB |
Output is correct |
226 |
Correct |
503 ms |
548 KB |
Output is correct |