#include "Anna.h"
#include <vector>
#include <iostream>
#include <assert.h>
using namespace std;
namespace {
inline int ab(int x) {
return x > 0 ? x : -x;
}
int getdir(int dx, int dy) {
int ret = 0;
if (dy > 1) ret = 0;
else if (dy < -1) ret = 1;
else if (dx > 1) ret = 2;
else ret = 3;
ret += 9;
return ret;
}
inline int encode(int dx, int dy) {
return (dx + 1) * 3 + (dy + 1) + 1;
}
bool check(int N, int K, vector<int> R, vector<int> C, int mv, bool set) {
int mx = mv / 3, my = mv % 3;
int ret[N][N];
bool found[10];
for (int i = 0;i < 10;i++) found[i] = false;
for (int i = 0;i < N;i++) {
for (int j = 0;j < N;j++) {
int val = ((i - mx + 3) % 3 * 3 + (j - my + 3) % 3);
if (val > 0 && val <= 7) {
int dx = R[val-1] - i, dy = C[val-1] - j;
if (ab(dx) > 1 || ab(dy) > 1) {
ret[i][j] = getdir(dx, dy);
} else {
ret[i][j] = encode(dx, dy);
if (encode(dx, dy) == 9) return false;
found[encode(dx, dy)] = true;
}
} else if (val == 0) {
ret[i][j] = 13;
} else {
ret[i][j] = 0;
}
}
}
int emp = 0;
for (int i = 1;i < 9;i++) {
if (!found[i]) {
emp = i;
break;
}
}
for (int i = 0;i < N;i++) {
for (int j = 0;j < N;j++) {
if (ret[i][j] == 0) ret[i][j] = emp;
else if (ret[i][j] > emp) {
ret[i][j]--;
}
if (set) {
SetFlag(i, j, ret[i][j]);
}
}
}
return true;
}
} // namespace
void Anna(int N, int K, vector<int> R, vector<int> C) {
for (int i = 0;i < 9;i++) {
if (check(N, K, R, C, i, false)) {
check(N, K, R, C, i, true);
break;
}
}
}
#include "Bruno.h"
#include <vector>
#include <iostream>
using namespace std;
namespace {
int inp[3][3];
int px[9], py[9];
int getans(int dx, int dy) {
int ret = 0;
if (dx == 0 && dy == 0) return 4;
if (dy > 0) ret = 0;
else if (dy < 0) ret = 1;
else if (dx > 0) ret = 2;
else ret = 3;
return ret;
}
} // namespace
vector<int> Bruno(int K, vector<int> value) {
int tx = 0, ty = 0;
for (int i = 0;i < 9;i++) {
if (value[i] == 12) {
tx = i / 3, ty = i % 3;
}
}
for (int i = 0;i < 9;i++) {
int id = (i / 3 - tx + 3) % 3 * 3 + (i % 3 - ty + 3) % 3;
inp[(i / 3 - tx + 3) % 3][(i % 3 - ty + 3) % 3] = value[i];
px[id] = i / 3;
py[id] = i % 3;
}
int emp = inp[2][2];
vector<int> ret;
for (int i = 0;i < 3;i++) {
for (int j = 0;j < 3;j++) {
int num = i * 3 + j;
if (num > 0 && num <= 7) {
if (inp[i][j] >= emp) inp[i][j]++;
if (inp[i][j] >= 9) {
ret.push_back(inp[i][j] - 9);
} else {
int dx = px[num] - 1 + (inp[i][j] - 1) / 3 - 1, dy = py[num] - 1 + (inp[i][j] - 1) % 3 - 1;
ret.push_back(getans(dx, dy));
}
}
}
}
return ret;
}
/*
1
7 7
1 2
1 3
3 2
3 5
4 1
5 3
5 5
4 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
728 KB |
Output is correct |
2 |
Correct |
17 ms |
728 KB |
Output is correct |
3 |
Correct |
15 ms |
728 KB |
Output is correct |
4 |
Correct |
14 ms |
728 KB |
Output is correct |
5 |
Correct |
16 ms |
728 KB |
Output is correct |
6 |
Correct |
13 ms |
728 KB |
Output is correct |
7 |
Correct |
14 ms |
728 KB |
Output is correct |
8 |
Correct |
16 ms |
728 KB |
Output is correct |
9 |
Correct |
16 ms |
728 KB |
Output is correct |
10 |
Correct |
19 ms |
728 KB |
Output is correct |
11 |
Correct |
16 ms |
728 KB |
Output is correct |
12 |
Correct |
13 ms |
728 KB |
Output is correct |
13 |
Correct |
14 ms |
728 KB |
Output is correct |
14 |
Correct |
15 ms |
728 KB |
Output is correct |
15 |
Correct |
12 ms |
728 KB |
Output is correct |
16 |
Correct |
18 ms |
728 KB |
Output is correct |
17 |
Correct |
18 ms |
728 KB |
Output is correct |
18 |
Correct |
13 ms |
680 KB |
Output is correct |
19 |
Correct |
18 ms |
744 KB |
Output is correct |
20 |
Correct |
19 ms |
728 KB |
Output is correct |
21 |
Correct |
15 ms |
728 KB |
Output is correct |
22 |
Correct |
13 ms |
732 KB |
Output is correct |
23 |
Correct |
15 ms |
728 KB |
Output is correct |
24 |
Correct |
16 ms |
728 KB |
Output is correct |
25 |
Correct |
13 ms |
728 KB |
Output is correct |
26 |
Correct |
18 ms |
728 KB |
Output is correct |
27 |
Correct |
17 ms |
728 KB |
Output is correct |
28 |
Correct |
19 ms |
728 KB |
Output is correct |
29 |
Correct |
13 ms |
732 KB |
Output is correct |
30 |
Correct |
15 ms |
728 KB |
Output is correct |
31 |
Correct |
20 ms |
728 KB |
Output is correct |
32 |
Correct |
15 ms |
728 KB |
Output is correct |
33 |
Correct |
17 ms |
728 KB |
Output is correct |
34 |
Correct |
17 ms |
728 KB |
Output is correct |
35 |
Correct |
17 ms |
728 KB |
Output is correct |
36 |
Correct |
13 ms |
728 KB |
Output is correct |
37 |
Correct |
15 ms |
728 KB |
Output is correct |
38 |
Correct |
15 ms |
728 KB |
Output is correct |
39 |
Correct |
16 ms |
728 KB |
Output is correct |
40 |
Correct |
17 ms |
728 KB |
Output is correct |
41 |
Correct |
22 ms |
728 KB |
Output is correct |
42 |
Correct |
13 ms |
728 KB |
Output is correct |
43 |
Correct |
20 ms |
728 KB |
Output is correct |
44 |
Correct |
15 ms |
728 KB |
Output is correct |
45 |
Correct |
15 ms |
728 KB |
Output is correct |
46 |
Correct |
17 ms |
728 KB |
Output is correct |
47 |
Correct |
18 ms |
728 KB |
Output is correct |
48 |
Correct |
15 ms |
728 KB |
Output is correct |
49 |
Correct |
16 ms |
728 KB |
Output is correct |
50 |
Correct |
24 ms |
856 KB |
Output is correct |
51 |
Correct |
19 ms |
728 KB |
Output is correct |
52 |
Correct |
18 ms |
728 KB |
Output is correct |
53 |
Correct |
19 ms |
728 KB |
Output is correct |
54 |
Correct |
16 ms |
728 KB |
Output is correct |
55 |
Correct |
20 ms |
728 KB |
Output is correct |
56 |
Correct |
25 ms |
728 KB |
Output is correct |
57 |
Correct |
24 ms |
728 KB |
Output is correct |
58 |
Correct |
24 ms |
728 KB |
Output is correct |
59 |
Correct |
18 ms |
728 KB |
Output is correct |
60 |
Correct |
20 ms |
728 KB |
Output is correct |
61 |
Correct |
18 ms |
732 KB |
Output is correct |
62 |
Correct |
24 ms |
728 KB |
Output is correct |
63 |
Correct |
22 ms |
732 KB |
Output is correct |
64 |
Correct |
25 ms |
728 KB |
Output is correct |
65 |
Correct |
19 ms |
728 KB |
Output is correct |
66 |
Correct |
19 ms |
728 KB |
Output is correct |
67 |
Correct |
19 ms |
728 KB |
Output is correct |
68 |
Correct |
22 ms |
728 KB |
Output is correct |
69 |
Correct |
20 ms |
728 KB |
Output is correct |
70 |
Correct |
20 ms |
728 KB |
Output is correct |
71 |
Correct |
23 ms |
728 KB |
Output is correct |
72 |
Correct |
23 ms |
856 KB |
Output is correct |
73 |
Correct |
19 ms |
728 KB |
Output is correct |
74 |
Correct |
26 ms |
728 KB |
Output is correct |
75 |
Correct |
22 ms |
744 KB |
Output is correct |
76 |
Correct |
24 ms |
728 KB |
Output is correct |
77 |
Correct |
25 ms |
728 KB |
Output is correct |
78 |
Correct |
20 ms |
728 KB |
Output is correct |
79 |
Correct |
25 ms |
728 KB |
Output is correct |
80 |
Correct |
22 ms |
728 KB |
Output is correct |
81 |
Correct |
20 ms |
772 KB |
Output is correct |
82 |
Correct |
20 ms |
728 KB |
Output is correct |
83 |
Correct |
20 ms |
728 KB |
Output is correct |
84 |
Correct |
20 ms |
728 KB |
Output is correct |
85 |
Correct |
22 ms |
728 KB |
Output is correct |
86 |
Correct |
19 ms |
728 KB |
Output is correct |
87 |
Correct |
20 ms |
728 KB |
Output is correct |
88 |
Correct |
22 ms |
728 KB |
Output is correct |
89 |
Correct |
25 ms |
728 KB |
Output is correct |
90 |
Correct |
22 ms |
728 KB |
Output is correct |
91 |
Correct |
19 ms |
732 KB |
Output is correct |
92 |
Correct |
20 ms |
728 KB |
Output is correct |
93 |
Correct |
20 ms |
728 KB |
Output is correct |
94 |
Correct |
20 ms |
728 KB |
Output is correct |
95 |
Correct |
27 ms |
728 KB |
Output is correct |
96 |
Correct |
23 ms |
732 KB |
Output is correct |
97 |
Correct |
19 ms |
728 KB |
Output is correct |
98 |
Correct |
21 ms |
732 KB |
Output is correct |
99 |
Correct |
26 ms |
728 KB |
Output is correct |
100 |
Correct |
20 ms |
728 KB |
Output is correct |
101 |
Correct |
20 ms |
728 KB |
Output is correct |
102 |
Correct |
18 ms |
728 KB |
Output is correct |
103 |
Correct |
23 ms |
728 KB |
Output is correct |
104 |
Correct |
20 ms |
728 KB |
Output is correct |
105 |
Correct |
23 ms |
728 KB |
Output is correct |
106 |
Correct |
26 ms |
728 KB |
Output is correct |
107 |
Correct |
19 ms |
724 KB |
Output is correct |
108 |
Correct |
27 ms |
728 KB |
Output is correct |
109 |
Correct |
20 ms |
728 KB |
Output is correct |
110 |
Correct |
20 ms |
728 KB |
Output is correct |
111 |
Correct |
20 ms |
728 KB |
Output is correct |
112 |
Correct |
26 ms |
728 KB |
Output is correct |
113 |
Correct |
26 ms |
728 KB |
Output is correct |
114 |
Correct |
23 ms |
728 KB |
Output is correct |
115 |
Correct |
20 ms |
728 KB |
Output is correct |
116 |
Correct |
20 ms |
728 KB |
Output is correct |
117 |
Correct |
25 ms |
728 KB |
Output is correct |
118 |
Correct |
20 ms |
728 KB |
Output is correct |
119 |
Correct |
26 ms |
728 KB |
Output is correct |
120 |
Correct |
840 ms |
852 KB |
Output is correct |
121 |
Correct |
874 ms |
1088 KB |
Output is correct |
122 |
Correct |
880 ms |
1068 KB |
Output is correct |
123 |
Correct |
875 ms |
1104 KB |
Output is correct |
124 |
Correct |
904 ms |
1088 KB |
Output is correct |
125 |
Correct |
878 ms |
912 KB |
Output is correct |
126 |
Correct |
871 ms |
980 KB |
Output is correct |
127 |
Correct |
857 ms |
1028 KB |
Output is correct |
128 |
Correct |
859 ms |
1024 KB |
Output is correct |
129 |
Correct |
848 ms |
1000 KB |
Output is correct |
130 |
Correct |
862 ms |
916 KB |
Output is correct |
131 |
Correct |
875 ms |
924 KB |
Output is correct |
132 |
Correct |
935 ms |
1096 KB |
Output is correct |
133 |
Correct |
832 ms |
900 KB |
Output is correct |
134 |
Correct |
920 ms |
1072 KB |
Output is correct |
135 |
Correct |
903 ms |
1056 KB |
Output is correct |
136 |
Correct |
821 ms |
956 KB |
Output is correct |
137 |
Correct |
834 ms |
944 KB |
Output is correct |
138 |
Correct |
817 ms |
824 KB |
Output is correct |
139 |
Correct |
846 ms |
988 KB |
Output is correct |
140 |
Correct |
880 ms |
1088 KB |
Output is correct |
141 |
Correct |
844 ms |
1020 KB |
Output is correct |
142 |
Correct |
873 ms |
1188 KB |
Output is correct |
143 |
Correct |
879 ms |
912 KB |
Output is correct |
144 |
Correct |
874 ms |
896 KB |
Output is correct |
145 |
Correct |
907 ms |
1056 KB |
Output is correct |
146 |
Correct |
843 ms |
1016 KB |
Output is correct |
147 |
Correct |
901 ms |
1036 KB |
Output is correct |
148 |
Correct |
843 ms |
888 KB |
Output is correct |
149 |
Correct |
909 ms |
1008 KB |
Output is correct |
150 |
Correct |
865 ms |
1080 KB |
Output is correct |
151 |
Correct |
990 ms |
1208 KB |
Output is correct |
152 |
Correct |
843 ms |
812 KB |
Output is correct |
153 |
Correct |
897 ms |
1084 KB |
Output is correct |
154 |
Correct |
870 ms |
1032 KB |
Output is correct |
155 |
Correct |
945 ms |
916 KB |
Output is correct |
156 |
Correct |
830 ms |
928 KB |
Output is correct |
157 |
Correct |
869 ms |
904 KB |
Output is correct |
158 |
Correct |
883 ms |
1220 KB |
Output is correct |
159 |
Correct |
842 ms |
952 KB |
Output is correct |
160 |
Correct |
901 ms |
992 KB |
Output is correct |
161 |
Correct |
896 ms |
1140 KB |
Output is correct |
162 |
Correct |
856 ms |
1028 KB |
Output is correct |
163 |
Correct |
893 ms |
1004 KB |
Output is correct |
164 |
Correct |
838 ms |
848 KB |
Output is correct |
165 |
Correct |
942 ms |
1072 KB |
Output is correct |
166 |
Correct |
900 ms |
844 KB |
Output is correct |
167 |
Correct |
917 ms |
1000 KB |
Output is correct |
168 |
Correct |
924 ms |
1064 KB |
Output is correct |
169 |
Correct |
848 ms |
1052 KB |
Output is correct |
170 |
Correct |
848 ms |
876 KB |
Output is correct |
171 |
Correct |
848 ms |
1100 KB |
Output is correct |
172 |
Correct |
863 ms |
960 KB |
Output is correct |
173 |
Correct |
897 ms |
940 KB |
Output is correct |
174 |
Correct |
892 ms |
932 KB |
Output is correct |
175 |
Correct |
913 ms |
892 KB |
Output is correct |
176 |
Correct |
863 ms |
1012 KB |
Output is correct |
177 |
Correct |
865 ms |
976 KB |
Output is correct |
178 |
Correct |
936 ms |
1064 KB |
Output is correct |
179 |
Correct |
901 ms |
976 KB |
Output is correct |
180 |
Correct |
882 ms |
928 KB |
Output is correct |
181 |
Correct |
904 ms |
1056 KB |
Output is correct |
182 |
Correct |
879 ms |
1032 KB |
Output is correct |
183 |
Correct |
822 ms |
1024 KB |
Output is correct |
184 |
Correct |
855 ms |
1016 KB |
Output is correct |
185 |
Correct |
832 ms |
896 KB |
Output is correct |
186 |
Correct |
858 ms |
944 KB |
Output is correct |
187 |
Correct |
893 ms |
980 KB |
Output is correct |
188 |
Correct |
896 ms |
1132 KB |
Output is correct |
189 |
Correct |
883 ms |
1060 KB |
Output is correct |
190 |
Correct |
885 ms |
1036 KB |
Output is correct |
191 |
Correct |
879 ms |
1020 KB |
Output is correct |
192 |
Correct |
884 ms |
976 KB |
Output is correct |
193 |
Correct |
871 ms |
1228 KB |
Output is correct |
194 |
Correct |
852 ms |
1000 KB |
Output is correct |
195 |
Correct |
882 ms |
1008 KB |
Output is correct |
196 |
Correct |
900 ms |
952 KB |
Output is correct |
197 |
Correct |
931 ms |
872 KB |
Output is correct |
198 |
Correct |
882 ms |
972 KB |
Output is correct |
199 |
Correct |
821 ms |
1064 KB |
Output is correct |
200 |
Correct |
983 ms |
1232 KB |
Output is correct |
201 |
Correct |
843 ms |
960 KB |
Output is correct |
202 |
Correct |
856 ms |
992 KB |
Output is correct |
203 |
Correct |
887 ms |
1012 KB |
Output is correct |
204 |
Correct |
860 ms |
984 KB |
Output is correct |
205 |
Correct |
939 ms |
1224 KB |
Output is correct |
206 |
Correct |
954 ms |
940 KB |
Output is correct |
207 |
Correct |
967 ms |
944 KB |
Output is correct |
208 |
Correct |
887 ms |
840 KB |
Output is correct |
209 |
Correct |
962 ms |
944 KB |
Output is correct |
210 |
Correct |
685 ms |
800 KB |
Output is correct |
211 |
Correct |
676 ms |
860 KB |
Output is correct |
212 |
Correct |
757 ms |
964 KB |
Output is correct |
213 |
Correct |
670 ms |
916 KB |
Output is correct |
214 |
Correct |
655 ms |
1048 KB |
Output is correct |
215 |
Correct |
666 ms |
888 KB |
Output is correct |
216 |
Correct |
677 ms |
972 KB |
Output is correct |
217 |
Correct |
628 ms |
896 KB |
Output is correct |
218 |
Correct |
606 ms |
1124 KB |
Output is correct |
219 |
Correct |
680 ms |
948 KB |
Output is correct |
220 |
Correct |
667 ms |
1012 KB |
Output is correct |
221 |
Correct |
752 ms |
820 KB |
Output is correct |
222 |
Correct |
624 ms |
992 KB |
Output is correct |
223 |
Correct |
630 ms |
916 KB |
Output is correct |
224 |
Correct |
709 ms |
932 KB |
Output is correct |
225 |
Correct |
628 ms |
904 KB |
Output is correct |
226 |
Correct |
652 ms |
1068 KB |
Output is correct |