#ifndef BALBIT
#include "Anna.h"
#endif
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#define pb push_back
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#endif // BALBIT
namespace {
const int maxn = 505;
int g[maxn][maxn];
int get(int r, int c, int tr, int tc) {
if (max(abs(r - tr) , abs(c - tc) ) <= 1) {
return (tr-r+1) * 3 + (tc - c+1) + 1;
}else{
if (r < tr-1) return 10; // r++
if (r > tr+1) return 11; // r--;
if (c < tc-1) return 12; // c++
if (c > tc+1) return 13; // c--;
}
}
int raw[maxn][maxn];
#ifdef BALBIT
void SetFlag(int a,int b, int c) {
bug(a,b,c);
assert(c>=1);
}
#endif // BALBIT
} // namespace
void Anna(int N, int K, vector<int> R, vector<int> C) {
vector<int> used(15);
int RS=0, LS=0; // R shift and L shift
for (RS=0; RS < 3; ++RS) for (LS=0; LS < 3; ++LS) {
fill(used.begin(),used.end(),0);
memset(raw, 0, sizeof raw);
memset(g, 0, sizeof g);
bool useone = 0;
for (int r = 0; r < N; r++) {
for (int c = 0; c < N; c++) {
int id = ((r+RS) % 3) * 3 + ((c+LS) % 3);
if (id < K) {
int yo = get(r, c, R[id],C[id]);
raw[r][c] = yo;
if (yo == 1) useone = 1;
used[yo] = 1;
}else{
if (id == K) {
// nope
}else{
raw[r][c] = 14;
used[14] = 1;
}
}
}
}
if (!useone) {
goto done;
}
}
done:;
assert(used[1] == 0);
bug(RS, LS);
int unused = 2;
while (used[unused]) ++unused;
for (int r = 0; r < N; r++) {
for (int c = 0; c < N; c++) {
int id = ((r+RS) % 3) * 3 + ((c+LS) % 3);
if (id == K) SetFlag(r,c,unused-1);
else {
SetFlag(r,c,(raw[r][c]>unused?raw[r][c]-1:raw[r][c])-1);
}
}
}
}
#ifdef BALBIT
signed main(){
Anna(7, 7, {2,2,2,3,3,3,4}, {2,3,4,2,3,4,2});
}
#endif
#include "Bruno.h"
#include <vector>
//#define BALBIT
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#define pb push_back
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#endif // BALBIT
namespace {
const int maxn = 505;
}
std::vector<int> Bruno(int K, std::vector<int> value) {
array<array<int, 5>, 5> tmp;
for (int &x:value)++x;
REP(i,5) REP(j,5) {
tmp[i][j] = (i % 3) * 3 + (j % 3);
// bug(i,j,tmp[i][j]);
}
for (int ti = 1; ti <= 3; ++ti) for (int tj = 1; tj <= 3; ++tj) {
// test it
vector<int> re(K);
bool ok = 1;
int it = 0;
for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) {
if (value[it] == 13) {
if (tmp[ti + di][tj + dj] <= K) {
ok = 0; goto nope;
}
}
++it;
}
bug(ti, tj);
assert(ok);
int gone;
int gi, gj;
it = 0;
for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) {
if (value[it] == 13) {
gi = di; gj = dj==-1?1:dj-1;
goto over1;
}
++it;
}
over1:;
it = 0;
for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) {
if (di == gi && dj == gj) {
gone = value[it];
goto over2;
}
++it;
}
over2:;
it = 0;
for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) {
if (value[it] >= gone) value[it] ++;
int hi = value[it];
bug(it, hi);
if (value[it] == 14) {
++it; continue;
}
int who = tmp[ti + di][tj + dj];
if (value[it] >= 10) {
if (value[it] == 10) re[who] = 2;
if (value[it] == 11) re[who] = 3;
if (value[it] == 12) re[who] = 0;
if (value[it] == 13) re[who] = 1;
}else{
int ai = di + ((hi-1)/3-1);
int aj = dj + ((hi-1)%3-1);
if (ai == 0 && aj == 0) {
re[who] = 4;
}else{
bug("from here!");
if (0 < ai) re[who] = 2;
if (0 > ai) re[who] = 3;
if (0 < aj) re[who] = 0;
if (0 > aj) re[who] = 1;
}
}
bug(it, who, re[who]);
++it;
}
return re;
nope:;
}
}
Compilation message
Anna.cpp: In function 'int {anonymous}::get(int, int, int, int)':
Anna.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
48 | }
| ^
Bruno.cpp: In function 'std::vector<int> Bruno(int, std::vector<int>)':
Bruno.cpp:125:5: warning: control reaches end of non-void function [-Wreturn-type]
125 | }
| ^
Bruno.cpp:89:17: warning: 'gone' may be used uninitialized in this function [-Wmaybe-uninitialized]
89 | if (value[it] >= gone) value[it] ++;
| ^~
Bruno.cpp:77:36: warning: 'gj' may be used uninitialized in this function [-Wmaybe-uninitialized]
77 | if (di == gi && dj == gj) {
| ~~~^~~~~
Bruno.cpp:77:24: warning: 'gi' may be used uninitialized in this function [-Wmaybe-uninitialized]
77 | if (di == gi && dj == gj) {
| ~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
2448 KB |
Output is correct |
2 |
Correct |
40 ms |
2576 KB |
Output is correct |
3 |
Correct |
40 ms |
2448 KB |
Output is correct |
4 |
Correct |
39 ms |
2448 KB |
Output is correct |
5 |
Correct |
36 ms |
2448 KB |
Output is correct |
6 |
Correct |
45 ms |
2448 KB |
Output is correct |
7 |
Correct |
41 ms |
2528 KB |
Output is correct |
8 |
Correct |
37 ms |
2528 KB |
Output is correct |
9 |
Correct |
44 ms |
2464 KB |
Output is correct |
10 |
Correct |
44 ms |
2448 KB |
Output is correct |
11 |
Correct |
38 ms |
2448 KB |
Output is correct |
12 |
Correct |
46 ms |
2448 KB |
Output is correct |
13 |
Correct |
39 ms |
2528 KB |
Output is correct |
14 |
Correct |
48 ms |
2532 KB |
Output is correct |
15 |
Correct |
51 ms |
2448 KB |
Output is correct |
16 |
Correct |
35 ms |
2528 KB |
Output is correct |
17 |
Correct |
35 ms |
2448 KB |
Output is correct |
18 |
Correct |
41 ms |
2448 KB |
Output is correct |
19 |
Correct |
43 ms |
2448 KB |
Output is correct |
20 |
Correct |
37 ms |
2536 KB |
Output is correct |
21 |
Correct |
40 ms |
2448 KB |
Output is correct |
22 |
Correct |
36 ms |
2524 KB |
Output is correct |
23 |
Correct |
47 ms |
2448 KB |
Output is correct |
24 |
Correct |
48 ms |
2448 KB |
Output is correct |
25 |
Correct |
44 ms |
2528 KB |
Output is correct |
26 |
Correct |
43 ms |
2448 KB |
Output is correct |
27 |
Correct |
35 ms |
2476 KB |
Output is correct |
28 |
Correct |
51 ms |
2528 KB |
Output is correct |
29 |
Correct |
47 ms |
2576 KB |
Output is correct |
30 |
Correct |
43 ms |
2448 KB |
Output is correct |
31 |
Correct |
37 ms |
2448 KB |
Output is correct |
32 |
Correct |
38 ms |
2528 KB |
Output is correct |
33 |
Correct |
49 ms |
2448 KB |
Output is correct |
34 |
Correct |
48 ms |
2532 KB |
Output is correct |
35 |
Correct |
37 ms |
2448 KB |
Output is correct |
36 |
Correct |
36 ms |
2448 KB |
Output is correct |
37 |
Correct |
43 ms |
2528 KB |
Output is correct |
38 |
Correct |
51 ms |
2448 KB |
Output is correct |
39 |
Correct |
37 ms |
2532 KB |
Output is correct |
40 |
Correct |
41 ms |
2448 KB |
Output is correct |
41 |
Correct |
46 ms |
2448 KB |
Output is correct |
42 |
Correct |
52 ms |
2536 KB |
Output is correct |
43 |
Correct |
48 ms |
2448 KB |
Output is correct |
44 |
Correct |
39 ms |
2448 KB |
Output is correct |
45 |
Correct |
49 ms |
2448 KB |
Output is correct |
46 |
Correct |
45 ms |
2448 KB |
Output is correct |
47 |
Correct |
48 ms |
2532 KB |
Output is correct |
48 |
Correct |
44 ms |
2448 KB |
Output is correct |
49 |
Correct |
43 ms |
2532 KB |
Output is correct |
50 |
Correct |
46 ms |
2448 KB |
Output is correct |
51 |
Correct |
47 ms |
2532 KB |
Output is correct |
52 |
Correct |
43 ms |
2448 KB |
Output is correct |
53 |
Correct |
44 ms |
2448 KB |
Output is correct |
54 |
Correct |
41 ms |
2528 KB |
Output is correct |
55 |
Correct |
38 ms |
2448 KB |
Output is correct |
56 |
Correct |
53 ms |
2448 KB |
Output is correct |
57 |
Correct |
60 ms |
2532 KB |
Output is correct |
58 |
Correct |
48 ms |
2448 KB |
Output is correct |
59 |
Correct |
59 ms |
2448 KB |
Output is correct |
60 |
Correct |
49 ms |
2448 KB |
Output is correct |
61 |
Correct |
59 ms |
2448 KB |
Output is correct |
62 |
Correct |
54 ms |
2448 KB |
Output is correct |
63 |
Correct |
47 ms |
2448 KB |
Output is correct |
64 |
Correct |
53 ms |
2448 KB |
Output is correct |
65 |
Correct |
51 ms |
2448 KB |
Output is correct |
66 |
Correct |
61 ms |
2448 KB |
Output is correct |
67 |
Correct |
60 ms |
2448 KB |
Output is correct |
68 |
Correct |
59 ms |
2448 KB |
Output is correct |
69 |
Correct |
51 ms |
2448 KB |
Output is correct |
70 |
Correct |
44 ms |
2528 KB |
Output is correct |
71 |
Correct |
56 ms |
2448 KB |
Output is correct |
72 |
Correct |
46 ms |
2448 KB |
Output is correct |
73 |
Correct |
47 ms |
2448 KB |
Output is correct |
74 |
Correct |
57 ms |
2448 KB |
Output is correct |
75 |
Correct |
60 ms |
2528 KB |
Output is correct |
76 |
Correct |
47 ms |
2536 KB |
Output is correct |
77 |
Correct |
56 ms |
2448 KB |
Output is correct |
78 |
Correct |
57 ms |
2448 KB |
Output is correct |
79 |
Correct |
48 ms |
2448 KB |
Output is correct |
80 |
Correct |
49 ms |
2448 KB |
Output is correct |
81 |
Correct |
46 ms |
2448 KB |
Output is correct |
82 |
Correct |
56 ms |
2448 KB |
Output is correct |
83 |
Correct |
53 ms |
2448 KB |
Output is correct |
84 |
Correct |
44 ms |
2448 KB |
Output is correct |
85 |
Correct |
54 ms |
2448 KB |
Output is correct |
86 |
Correct |
59 ms |
2448 KB |
Output is correct |
87 |
Correct |
59 ms |
2448 KB |
Output is correct |
88 |
Correct |
54 ms |
2448 KB |
Output is correct |
89 |
Correct |
45 ms |
2532 KB |
Output is correct |
90 |
Correct |
48 ms |
2448 KB |
Output is correct |
91 |
Correct |
57 ms |
2448 KB |
Output is correct |
92 |
Correct |
62 ms |
2468 KB |
Output is correct |
93 |
Correct |
57 ms |
2448 KB |
Output is correct |
94 |
Correct |
61 ms |
2448 KB |
Output is correct |
95 |
Correct |
44 ms |
2448 KB |
Output is correct |
96 |
Correct |
52 ms |
2528 KB |
Output is correct |
97 |
Correct |
49 ms |
2448 KB |
Output is correct |
98 |
Correct |
55 ms |
2528 KB |
Output is correct |
99 |
Correct |
57 ms |
2448 KB |
Output is correct |
100 |
Correct |
59 ms |
2536 KB |
Output is correct |
101 |
Correct |
53 ms |
2448 KB |
Output is correct |
102 |
Correct |
59 ms |
2448 KB |
Output is correct |
103 |
Correct |
56 ms |
2448 KB |
Output is correct |
104 |
Correct |
63 ms |
2448 KB |
Output is correct |
105 |
Correct |
48 ms |
2448 KB |
Output is correct |
106 |
Correct |
51 ms |
2448 KB |
Output is correct |
107 |
Correct |
47 ms |
2532 KB |
Output is correct |
108 |
Correct |
47 ms |
2448 KB |
Output is correct |
109 |
Correct |
47 ms |
2448 KB |
Output is correct |
110 |
Correct |
53 ms |
2448 KB |
Output is correct |
111 |
Correct |
48 ms |
2528 KB |
Output is correct |
112 |
Correct |
51 ms |
2448 KB |
Output is correct |
113 |
Correct |
48 ms |
2536 KB |
Output is correct |
114 |
Correct |
57 ms |
2448 KB |
Output is correct |
115 |
Correct |
48 ms |
2528 KB |
Output is correct |
116 |
Correct |
47 ms |
2448 KB |
Output is correct |
117 |
Correct |
59 ms |
2448 KB |
Output is correct |
118 |
Correct |
59 ms |
2448 KB |
Output is correct |
119 |
Correct |
56 ms |
2528 KB |
Output is correct |
120 |
Correct |
663 ms |
2552 KB |
Output is correct |
121 |
Correct |
670 ms |
2924 KB |
Output is correct |
122 |
Correct |
690 ms |
2676 KB |
Output is correct |
123 |
Correct |
656 ms |
2636 KB |
Output is correct |
124 |
Correct |
597 ms |
2592 KB |
Output is correct |
125 |
Correct |
623 ms |
2660 KB |
Output is correct |
126 |
Correct |
676 ms |
2716 KB |
Output is correct |
127 |
Correct |
751 ms |
2612 KB |
Output is correct |
128 |
Correct |
697 ms |
2680 KB |
Output is correct |
129 |
Correct |
820 ms |
2668 KB |
Output is correct |
130 |
Correct |
749 ms |
2612 KB |
Output is correct |
131 |
Correct |
894 ms |
2620 KB |
Output is correct |
132 |
Correct |
760 ms |
2708 KB |
Output is correct |
133 |
Correct |
954 ms |
2552 KB |
Output is correct |
134 |
Correct |
645 ms |
2728 KB |
Output is correct |
135 |
Correct |
636 ms |
2680 KB |
Output is correct |
136 |
Correct |
773 ms |
2944 KB |
Output is correct |
137 |
Correct |
659 ms |
2712 KB |
Output is correct |
138 |
Correct |
712 ms |
2800 KB |
Output is correct |
139 |
Correct |
636 ms |
2628 KB |
Output is correct |
140 |
Correct |
755 ms |
2784 KB |
Output is correct |
141 |
Correct |
679 ms |
2744 KB |
Output is correct |
142 |
Correct |
671 ms |
2504 KB |
Output is correct |
143 |
Correct |
690 ms |
2600 KB |
Output is correct |
144 |
Correct |
774 ms |
2820 KB |
Output is correct |
145 |
Correct |
653 ms |
2672 KB |
Output is correct |
146 |
Correct |
679 ms |
2808 KB |
Output is correct |
147 |
Correct |
695 ms |
2732 KB |
Output is correct |
148 |
Correct |
667 ms |
2776 KB |
Output is correct |
149 |
Correct |
620 ms |
2532 KB |
Output is correct |
150 |
Correct |
611 ms |
2740 KB |
Output is correct |
151 |
Correct |
664 ms |
2592 KB |
Output is correct |
152 |
Correct |
613 ms |
2688 KB |
Output is correct |
153 |
Correct |
629 ms |
2832 KB |
Output is correct |
154 |
Correct |
687 ms |
2648 KB |
Output is correct |
155 |
Correct |
634 ms |
2780 KB |
Output is correct |
156 |
Correct |
671 ms |
2772 KB |
Output is correct |
157 |
Correct |
636 ms |
2776 KB |
Output is correct |
158 |
Correct |
627 ms |
2716 KB |
Output is correct |
159 |
Correct |
666 ms |
2692 KB |
Output is correct |
160 |
Correct |
617 ms |
2576 KB |
Output is correct |
161 |
Correct |
681 ms |
2704 KB |
Output is correct |
162 |
Correct |
637 ms |
2592 KB |
Output is correct |
163 |
Correct |
621 ms |
2600 KB |
Output is correct |
164 |
Correct |
673 ms |
3040 KB |
Output is correct |
165 |
Correct |
655 ms |
2716 KB |
Output is correct |
166 |
Correct |
689 ms |
2792 KB |
Output is correct |
167 |
Correct |
620 ms |
2796 KB |
Output is correct |
168 |
Correct |
615 ms |
2616 KB |
Output is correct |
169 |
Correct |
628 ms |
2588 KB |
Output is correct |
170 |
Correct |
671 ms |
2652 KB |
Output is correct |
171 |
Correct |
676 ms |
2740 KB |
Output is correct |
172 |
Correct |
684 ms |
2736 KB |
Output is correct |
173 |
Correct |
655 ms |
2776 KB |
Output is correct |
174 |
Correct |
674 ms |
2720 KB |
Output is correct |
175 |
Correct |
652 ms |
2804 KB |
Output is correct |
176 |
Correct |
658 ms |
2620 KB |
Output is correct |
177 |
Correct |
636 ms |
2732 KB |
Output is correct |
178 |
Correct |
702 ms |
2760 KB |
Output is correct |
179 |
Correct |
643 ms |
2828 KB |
Output is correct |
180 |
Correct |
699 ms |
2684 KB |
Output is correct |
181 |
Correct |
659 ms |
2668 KB |
Output is correct |
182 |
Correct |
629 ms |
2672 KB |
Output is correct |
183 |
Correct |
609 ms |
2740 KB |
Output is correct |
184 |
Correct |
593 ms |
2728 KB |
Output is correct |
185 |
Correct |
615 ms |
2556 KB |
Output is correct |
186 |
Correct |
647 ms |
2732 KB |
Output is correct |
187 |
Correct |
610 ms |
2816 KB |
Output is correct |
188 |
Correct |
652 ms |
2656 KB |
Output is correct |
189 |
Correct |
711 ms |
2728 KB |
Output is correct |
190 |
Correct |
629 ms |
2616 KB |
Output is correct |
191 |
Correct |
678 ms |
2672 KB |
Output is correct |
192 |
Correct |
623 ms |
2736 KB |
Output is correct |
193 |
Correct |
634 ms |
2640 KB |
Output is correct |
194 |
Correct |
640 ms |
2728 KB |
Output is correct |
195 |
Correct |
657 ms |
2556 KB |
Output is correct |
196 |
Correct |
692 ms |
2612 KB |
Output is correct |
197 |
Correct |
596 ms |
2676 KB |
Output is correct |
198 |
Correct |
597 ms |
2680 KB |
Output is correct |
199 |
Correct |
682 ms |
2732 KB |
Output is correct |
200 |
Correct |
624 ms |
2796 KB |
Output is correct |
201 |
Correct |
662 ms |
2732 KB |
Output is correct |
202 |
Correct |
661 ms |
2604 KB |
Output is correct |
203 |
Correct |
603 ms |
2516 KB |
Output is correct |
204 |
Correct |
623 ms |
2696 KB |
Output is correct |
205 |
Correct |
624 ms |
2580 KB |
Output is correct |
206 |
Correct |
632 ms |
2676 KB |
Output is correct |
207 |
Correct |
655 ms |
2712 KB |
Output is correct |
208 |
Correct |
656 ms |
2796 KB |
Output is correct |
209 |
Correct |
646 ms |
2752 KB |
Output is correct |
210 |
Correct |
506 ms |
2680 KB |
Output is correct |
211 |
Correct |
502 ms |
2732 KB |
Output is correct |
212 |
Correct |
488 ms |
2692 KB |
Output is correct |
213 |
Correct |
487 ms |
2708 KB |
Output is correct |
214 |
Correct |
495 ms |
2620 KB |
Output is correct |
215 |
Correct |
476 ms |
2572 KB |
Output is correct |
216 |
Correct |
520 ms |
2700 KB |
Output is correct |
217 |
Correct |
630 ms |
2728 KB |
Output is correct |
218 |
Correct |
562 ms |
2692 KB |
Output is correct |
219 |
Correct |
539 ms |
2656 KB |
Output is correct |
220 |
Correct |
492 ms |
2632 KB |
Output is correct |
221 |
Correct |
523 ms |
2624 KB |
Output is correct |
222 |
Correct |
503 ms |
2656 KB |
Output is correct |
223 |
Correct |
497 ms |
2588 KB |
Output is correct |
224 |
Correct |
579 ms |
2564 KB |
Output is correct |
225 |
Correct |
565 ms |
2748 KB |
Output is correct |
226 |
Correct |
613 ms |
2596 KB |
Output is correct |