#include "Anna.h"
#include <cmath>
#include <vector>
namespace {
const int kMark = 13;
std::vector<std::vector<int>> flag;
void init(const int& N) {
flag.assign(N, std::vector<int>(N, 0));
}
int get_val(const int& i, const int& j, const int& r, const int& c) {
if (j <= c - 2) return 9;
if (j >= c + 2) return 10;
if (i <= r - 2) return 11;
if (i >= r + 2) return 12;
int di = i - r, dj = j - c;
int val = (di + 1) * 3 + (dj + 1) + 1;
return (val == 9 ? -1 : val);
}
bool solve(const int& N, const int& K, const std::vector<int>& R, const std::vector<int>& C, const int& offset) {
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
int k = ((i + offset / 3) % 3) * 3 + ((j + offset % 3) % 3);
flag[i][j] = (k < 7 ? get_val(i, j, R[k], C[k]) : (k == 8 ? kMark : 0));
if (flag[i][j] == -1) return false;
}
return true;
}
} // namespace
void Anna(int N, int K, std::vector<int> R, std::vector<int> C) {
init(N);
for (int i = 0; i < 9; ++i)
if (solve(N, K, R, C, i)) break;
std::vector<bool> used(kMark + 1, false);
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
used[flag[i][j]] = true;
int no_use;
for (int i = 0; i <= kMark; ++i)
if (!used[i]) {
no_use = i;
break;
}
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j) {
if (flag[i][j] > no_use) --flag[i][j];
if (flag[i][j] == 0) flag[i][j] = no_use;
SetFlag(i, j, flag[i][j]);
}
}
#include "Bruno.h"
#include <vector>
#include <iostream>
namespace {
const int kMark = 12;
int judge(const int& i, const int& j, const int& r, const int& c) {
if (i == r and j == c) return 4;
if (j < c) return 0;
if (j > c) return 1;
if (i < r) return 2;
if (i > r) return 3;
return -1;
}
} // namespace
std::vector<int> Bruno(int K, std::vector<int> value) {
int mark_i, mark_j, no_use;
for (int i = 0; i < 9; ++i)
if (value[i] == kMark) {
mark_i = i / 3;
mark_j = i % 3;
}
no_use = value[mark_i * 3 + (mark_j + 2) % 3];
std::vector<int> res(K);
for (int dk = 0; dk < 9; ++dk) {
int i = (dk / 3 + 2 - mark_i) % 3, j = (dk % 3 + 2 - mark_j) % 3;
int k = i * 3 + j;
if (i * 3 + j >= 7) continue;
if (value[dk] >= no_use) ++value[dk];
if (value[dk] >= 9) res[k] = value[dk] - 9;
else {
int r = dk / 3 + (1 - (value[dk] - 1) / 3);
int c = dk % 3 + (1 - (value[dk] - 1) % 3);
res[k] = judge(1, 1, r, c);
}
}
return res;
}
Compilation message
Anna.cpp: In function 'void Anna(int, int, std::vector<int>, std::vector<int>)':
Anna.cpp:55:36: warning: 'no_use' may be used uninitialized in this function [-Wmaybe-uninitialized]
55 | if (flag[i][j] == 0) flag[i][j] = no_use;
Bruno.cpp: In function 'std::vector<int> Bruno(int, std::vector<int>)':
Bruno.cpp:31:54: warning: 'mark_j' may be used uninitialized in this function [-Wmaybe-uninitialized]
31 | int i = (dk / 3 + 2 - mark_i) % 3, j = (dk % 3 + 2 - mark_j) % 3;
| ~~~~~~~~~~~~^~~~~~~~~
Bruno.cpp:31:23: warning: 'mark_i' may be used uninitialized in this function [-Wmaybe-uninitialized]
31 | int i = (dk / 3 + 2 - mark_i) % 3, j = (dk % 3 + 2 - mark_j) % 3;
| ~~~~~~~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
392 KB |
Output is correct |
2 |
Correct |
12 ms |
392 KB |
Output is correct |
3 |
Correct |
10 ms |
432 KB |
Output is correct |
4 |
Correct |
10 ms |
392 KB |
Output is correct |
5 |
Correct |
13 ms |
392 KB |
Output is correct |
6 |
Correct |
15 ms |
392 KB |
Output is correct |
7 |
Correct |
13 ms |
476 KB |
Output is correct |
8 |
Correct |
12 ms |
392 KB |
Output is correct |
9 |
Correct |
11 ms |
392 KB |
Output is correct |
10 |
Correct |
12 ms |
392 KB |
Output is correct |
11 |
Correct |
13 ms |
392 KB |
Output is correct |
12 |
Correct |
16 ms |
392 KB |
Output is correct |
13 |
Correct |
13 ms |
392 KB |
Output is correct |
14 |
Correct |
14 ms |
392 KB |
Output is correct |
15 |
Correct |
15 ms |
392 KB |
Output is correct |
16 |
Correct |
13 ms |
392 KB |
Output is correct |
17 |
Correct |
12 ms |
392 KB |
Output is correct |
18 |
Correct |
14 ms |
392 KB |
Output is correct |
19 |
Correct |
13 ms |
392 KB |
Output is correct |
20 |
Correct |
11 ms |
392 KB |
Output is correct |
21 |
Correct |
15 ms |
392 KB |
Output is correct |
22 |
Correct |
14 ms |
476 KB |
Output is correct |
23 |
Correct |
16 ms |
392 KB |
Output is correct |
24 |
Correct |
15 ms |
392 KB |
Output is correct |
25 |
Correct |
12 ms |
392 KB |
Output is correct |
26 |
Correct |
12 ms |
392 KB |
Output is correct |
27 |
Correct |
11 ms |
392 KB |
Output is correct |
28 |
Correct |
13 ms |
392 KB |
Output is correct |
29 |
Correct |
16 ms |
392 KB |
Output is correct |
30 |
Correct |
13 ms |
392 KB |
Output is correct |
31 |
Correct |
13 ms |
392 KB |
Output is correct |
32 |
Correct |
17 ms |
392 KB |
Output is correct |
33 |
Correct |
15 ms |
392 KB |
Output is correct |
34 |
Correct |
16 ms |
392 KB |
Output is correct |
35 |
Correct |
15 ms |
392 KB |
Output is correct |
36 |
Correct |
12 ms |
392 KB |
Output is correct |
37 |
Correct |
11 ms |
392 KB |
Output is correct |
38 |
Correct |
14 ms |
392 KB |
Output is correct |
39 |
Correct |
13 ms |
392 KB |
Output is correct |
40 |
Correct |
14 ms |
392 KB |
Output is correct |
41 |
Correct |
18 ms |
400 KB |
Output is correct |
42 |
Correct |
18 ms |
392 KB |
Output is correct |
43 |
Correct |
14 ms |
392 KB |
Output is correct |
44 |
Correct |
14 ms |
392 KB |
Output is correct |
45 |
Correct |
14 ms |
392 KB |
Output is correct |
46 |
Correct |
16 ms |
392 KB |
Output is correct |
47 |
Correct |
14 ms |
392 KB |
Output is correct |
48 |
Correct |
18 ms |
392 KB |
Output is correct |
49 |
Correct |
18 ms |
392 KB |
Output is correct |
50 |
Correct |
19 ms |
392 KB |
Output is correct |
51 |
Correct |
15 ms |
392 KB |
Output is correct |
52 |
Correct |
14 ms |
392 KB |
Output is correct |
53 |
Correct |
15 ms |
392 KB |
Output is correct |
54 |
Correct |
15 ms |
392 KB |
Output is correct |
55 |
Correct |
15 ms |
392 KB |
Output is correct |
56 |
Correct |
21 ms |
472 KB |
Output is correct |
57 |
Correct |
18 ms |
392 KB |
Output is correct |
58 |
Correct |
20 ms |
392 KB |
Output is correct |
59 |
Correct |
17 ms |
392 KB |
Output is correct |
60 |
Correct |
16 ms |
392 KB |
Output is correct |
61 |
Correct |
16 ms |
392 KB |
Output is correct |
62 |
Correct |
15 ms |
392 KB |
Output is correct |
63 |
Correct |
20 ms |
392 KB |
Output is correct |
64 |
Correct |
16 ms |
392 KB |
Output is correct |
65 |
Correct |
22 ms |
392 KB |
Output is correct |
66 |
Correct |
16 ms |
392 KB |
Output is correct |
67 |
Correct |
18 ms |
392 KB |
Output is correct |
68 |
Correct |
17 ms |
392 KB |
Output is correct |
69 |
Correct |
16 ms |
392 KB |
Output is correct |
70 |
Correct |
22 ms |
392 KB |
Output is correct |
71 |
Correct |
20 ms |
468 KB |
Output is correct |
72 |
Correct |
19 ms |
392 KB |
Output is correct |
73 |
Correct |
23 ms |
392 KB |
Output is correct |
74 |
Correct |
19 ms |
392 KB |
Output is correct |
75 |
Correct |
17 ms |
392 KB |
Output is correct |
76 |
Correct |
14 ms |
392 KB |
Output is correct |
77 |
Correct |
19 ms |
392 KB |
Output is correct |
78 |
Correct |
19 ms |
392 KB |
Output is correct |
79 |
Correct |
17 ms |
392 KB |
Output is correct |
80 |
Correct |
20 ms |
392 KB |
Output is correct |
81 |
Correct |
15 ms |
480 KB |
Output is correct |
82 |
Correct |
18 ms |
392 KB |
Output is correct |
83 |
Correct |
22 ms |
392 KB |
Output is correct |
84 |
Correct |
18 ms |
400 KB |
Output is correct |
85 |
Correct |
13 ms |
392 KB |
Output is correct |
86 |
Correct |
16 ms |
392 KB |
Output is correct |
87 |
Correct |
19 ms |
392 KB |
Output is correct |
88 |
Correct |
17 ms |
392 KB |
Output is correct |
89 |
Correct |
20 ms |
392 KB |
Output is correct |
90 |
Correct |
22 ms |
392 KB |
Output is correct |
91 |
Correct |
22 ms |
392 KB |
Output is correct |
92 |
Correct |
23 ms |
392 KB |
Output is correct |
93 |
Correct |
18 ms |
392 KB |
Output is correct |
94 |
Correct |
19 ms |
392 KB |
Output is correct |
95 |
Correct |
20 ms |
392 KB |
Output is correct |
96 |
Correct |
17 ms |
392 KB |
Output is correct |
97 |
Correct |
20 ms |
392 KB |
Output is correct |
98 |
Correct |
18 ms |
392 KB |
Output is correct |
99 |
Correct |
19 ms |
472 KB |
Output is correct |
100 |
Correct |
17 ms |
392 KB |
Output is correct |
101 |
Correct |
19 ms |
392 KB |
Output is correct |
102 |
Correct |
19 ms |
392 KB |
Output is correct |
103 |
Correct |
20 ms |
392 KB |
Output is correct |
104 |
Correct |
21 ms |
400 KB |
Output is correct |
105 |
Correct |
19 ms |
392 KB |
Output is correct |
106 |
Correct |
16 ms |
392 KB |
Output is correct |
107 |
Correct |
17 ms |
392 KB |
Output is correct |
108 |
Correct |
19 ms |
392 KB |
Output is correct |
109 |
Correct |
22 ms |
392 KB |
Output is correct |
110 |
Correct |
18 ms |
392 KB |
Output is correct |
111 |
Correct |
17 ms |
392 KB |
Output is correct |
112 |
Correct |
17 ms |
392 KB |
Output is correct |
113 |
Correct |
17 ms |
472 KB |
Output is correct |
114 |
Correct |
13 ms |
392 KB |
Output is correct |
115 |
Correct |
16 ms |
452 KB |
Output is correct |
116 |
Correct |
15 ms |
476 KB |
Output is correct |
117 |
Correct |
20 ms |
392 KB |
Output is correct |
118 |
Correct |
20 ms |
392 KB |
Output is correct |
119 |
Correct |
20 ms |
392 KB |
Output is correct |
120 |
Correct |
812 ms |
820 KB |
Output is correct |
121 |
Correct |
718 ms |
788 KB |
Output is correct |
122 |
Correct |
762 ms |
688 KB |
Output is correct |
123 |
Correct |
660 ms |
620 KB |
Output is correct |
124 |
Correct |
651 ms |
660 KB |
Output is correct |
125 |
Correct |
636 ms |
592 KB |
Output is correct |
126 |
Correct |
664 ms |
748 KB |
Output is correct |
127 |
Correct |
711 ms |
660 KB |
Output is correct |
128 |
Correct |
678 ms |
716 KB |
Output is correct |
129 |
Correct |
664 ms |
796 KB |
Output is correct |
130 |
Correct |
714 ms |
568 KB |
Output is correct |
131 |
Correct |
708 ms |
528 KB |
Output is correct |
132 |
Correct |
657 ms |
588 KB |
Output is correct |
133 |
Correct |
666 ms |
808 KB |
Output is correct |
134 |
Correct |
664 ms |
768 KB |
Output is correct |
135 |
Correct |
640 ms |
704 KB |
Output is correct |
136 |
Correct |
848 ms |
580 KB |
Output is correct |
137 |
Correct |
730 ms |
776 KB |
Output is correct |
138 |
Correct |
640 ms |
900 KB |
Output is correct |
139 |
Correct |
686 ms |
792 KB |
Output is correct |
140 |
Correct |
683 ms |
700 KB |
Output is correct |
141 |
Correct |
773 ms |
888 KB |
Output is correct |
142 |
Correct |
706 ms |
580 KB |
Output is correct |
143 |
Correct |
759 ms |
804 KB |
Output is correct |
144 |
Correct |
723 ms |
832 KB |
Output is correct |
145 |
Correct |
766 ms |
664 KB |
Output is correct |
146 |
Correct |
692 ms |
612 KB |
Output is correct |
147 |
Correct |
720 ms |
704 KB |
Output is correct |
148 |
Correct |
742 ms |
708 KB |
Output is correct |
149 |
Correct |
713 ms |
812 KB |
Output is correct |
150 |
Correct |
709 ms |
692 KB |
Output is correct |
151 |
Correct |
660 ms |
728 KB |
Output is correct |
152 |
Correct |
693 ms |
720 KB |
Output is correct |
153 |
Correct |
706 ms |
680 KB |
Output is correct |
154 |
Correct |
738 ms |
732 KB |
Output is correct |
155 |
Correct |
740 ms |
680 KB |
Output is correct |
156 |
Correct |
760 ms |
732 KB |
Output is correct |
157 |
Correct |
636 ms |
724 KB |
Output is correct |
158 |
Correct |
703 ms |
796 KB |
Output is correct |
159 |
Correct |
672 ms |
636 KB |
Output is correct |
160 |
Correct |
784 ms |
596 KB |
Output is correct |
161 |
Correct |
644 ms |
704 KB |
Output is correct |
162 |
Correct |
688 ms |
688 KB |
Output is correct |
163 |
Correct |
740 ms |
704 KB |
Output is correct |
164 |
Correct |
667 ms |
768 KB |
Output is correct |
165 |
Correct |
755 ms |
800 KB |
Output is correct |
166 |
Correct |
743 ms |
584 KB |
Output is correct |
167 |
Correct |
641 ms |
568 KB |
Output is correct |
168 |
Correct |
742 ms |
672 KB |
Output is correct |
169 |
Correct |
810 ms |
756 KB |
Output is correct |
170 |
Correct |
684 ms |
724 KB |
Output is correct |
171 |
Correct |
686 ms |
652 KB |
Output is correct |
172 |
Correct |
671 ms |
644 KB |
Output is correct |
173 |
Correct |
717 ms |
708 KB |
Output is correct |
174 |
Correct |
619 ms |
744 KB |
Output is correct |
175 |
Correct |
663 ms |
1008 KB |
Output is correct |
176 |
Correct |
629 ms |
820 KB |
Output is correct |
177 |
Correct |
612 ms |
616 KB |
Output is correct |
178 |
Correct |
674 ms |
660 KB |
Output is correct |
179 |
Correct |
625 ms |
732 KB |
Output is correct |
180 |
Correct |
678 ms |
640 KB |
Output is correct |
181 |
Correct |
622 ms |
760 KB |
Output is correct |
182 |
Correct |
662 ms |
760 KB |
Output is correct |
183 |
Correct |
625 ms |
748 KB |
Output is correct |
184 |
Correct |
649 ms |
732 KB |
Output is correct |
185 |
Correct |
629 ms |
796 KB |
Output is correct |
186 |
Correct |
685 ms |
624 KB |
Output is correct |
187 |
Correct |
763 ms |
844 KB |
Output is correct |
188 |
Correct |
745 ms |
728 KB |
Output is correct |
189 |
Correct |
615 ms |
716 KB |
Output is correct |
190 |
Correct |
681 ms |
592 KB |
Output is correct |
191 |
Correct |
624 ms |
668 KB |
Output is correct |
192 |
Correct |
687 ms |
620 KB |
Output is correct |
193 |
Correct |
636 ms |
628 KB |
Output is correct |
194 |
Correct |
621 ms |
596 KB |
Output is correct |
195 |
Correct |
619 ms |
660 KB |
Output is correct |
196 |
Correct |
640 ms |
700 KB |
Output is correct |
197 |
Correct |
805 ms |
612 KB |
Output is correct |
198 |
Correct |
668 ms |
768 KB |
Output is correct |
199 |
Correct |
594 ms |
704 KB |
Output is correct |
200 |
Correct |
593 ms |
684 KB |
Output is correct |
201 |
Correct |
636 ms |
664 KB |
Output is correct |
202 |
Correct |
724 ms |
592 KB |
Output is correct |
203 |
Correct |
646 ms |
564 KB |
Output is correct |
204 |
Correct |
633 ms |
624 KB |
Output is correct |
205 |
Correct |
674 ms |
660 KB |
Output is correct |
206 |
Correct |
596 ms |
724 KB |
Output is correct |
207 |
Correct |
737 ms |
636 KB |
Output is correct |
208 |
Correct |
698 ms |
616 KB |
Output is correct |
209 |
Correct |
667 ms |
800 KB |
Output is correct |
210 |
Correct |
488 ms |
668 KB |
Output is correct |
211 |
Correct |
460 ms |
748 KB |
Output is correct |
212 |
Correct |
591 ms |
744 KB |
Output is correct |
213 |
Correct |
597 ms |
808 KB |
Output is correct |
214 |
Correct |
512 ms |
572 KB |
Output is correct |
215 |
Correct |
501 ms |
764 KB |
Output is correct |
216 |
Correct |
538 ms |
672 KB |
Output is correct |
217 |
Correct |
612 ms |
604 KB |
Output is correct |
218 |
Correct |
566 ms |
740 KB |
Output is correct |
219 |
Correct |
581 ms |
576 KB |
Output is correct |
220 |
Correct |
490 ms |
588 KB |
Output is correct |
221 |
Correct |
509 ms |
564 KB |
Output is correct |
222 |
Correct |
635 ms |
712 KB |
Output is correct |
223 |
Correct |
628 ms |
676 KB |
Output is correct |
224 |
Correct |
507 ms |
716 KB |
Output is correct |
225 |
Correct |
508 ms |
632 KB |
Output is correct |
226 |
Correct |
600 ms |
840 KB |
Output is correct |