#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int tc, n, m, k, col;
vector<vector<int>> v;
map<ll, bool> can;
ll kN = 2e5;
#define hash sateiadracu
ll hash(int n, int m, int k) {
return kN * kN * n + kN * m + k;
}
bool check(int n, int m, int k) {
if(n > m) {
swap(n, m);
}
ll h = hash(n, m, k);
return can.find(h) != can.end() && can[h];
}
bool solve(int n, int m, int k) {
if(n % 2 || m % 2) {
return 0;
}
if(k > n * m / 4) {
return 0;
}
if(n > m) {
swap(n, m);
}
if(k < m / 2) {
return 0;
}
ll h = hash(n, m, k);
if(can.find(h) != can.end()) {
return can[h];
}
if(k == 1) {
return can[h] = (n == 2 && m == 2);
}
// split col
for(int k1 = 1; k1 < k; k1++) {
for(int j = 2; j < m - 1; j += 2) {
if(solve(n, j, k1) && solve(n, m - j, k - k1)) {
return can[h] = true;
}
}
}
// slpit border
if(solve(n - 2, m - 2, k - 1)) {
return can[h] = true;
}
return can[h] = false;
}
void rec(int a, int b, int c, int d, int k) {
int n = c - a + 1, m = d - b + 1;
if(n == 1 || m == 1) {
return;
}
if(k == 1) {
if(n == 2 && m == 2) {
v[a][b] = v[a][d] = v[c][b] = v[c][d] = col;
col++;
}
return;
}
if(check(c - a - 1, d - b - 1, k - 1)) {
for(int i = b; i <= d; i++) {
v[a][i] = v[c][i] = col;
}
for(int i = a; i <= c; i++) {
v[i][b] = v[i][d] = col;
}
col++;
rec(a + 1, b + 1, c - 1, d - 1, k - 1);
return;
}
for(int j = b + 1; j < d; j++) {
for(int k1 = 1; k1 < k; k1++) {
if(check(c - a + 1, j - b + 1, k1) && check(c - a + 1, d - j, k - k1)) {
rec(a, b, c, j, k1);
rec(a, j + 1, c, d, k - k1);
return;
}
}
}
for(int j = a + 1; j < c; j++) {
for(int k1 = 1; k1 < k; k1++) {
if(check(j - a + 1, d - b + 1, k1) && check(c - j, d - b + 1, k - k1)) {
rec(a, b, j, d, k1);
rec(j + 1, b, c, d, k - k1);
return;
}
}
}
}
void solve() {
cin >> n >> m >> k;
can.clear();
bool ok = solve(n, m, k);
if(!ok) {
cout << "NO\n";
return;
}
cout << "YES\n";
v = vector<vector<int>>(n + 1, vector<int>(m + 1));
col = 1;
rec(1, 1, n, m, k);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cout << v[i][j] << " ";
}
cout << "\n";
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> tc;
while(tc--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
856 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
856 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
13 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
652 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
856 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
13 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
652 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
11 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
13 ms |
820 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
77 ms |
992 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
59 ms |
1104 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
83 ms |
816 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
76 ms |
1160 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
70 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
72 ms |
1080 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
53 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
63 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
64 ms |
852 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
70 ms |
728 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
66 ms |
944 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
73 ms |
976 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
39 ms |
704 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
19 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
43 ms |
780 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
38 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
19 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
40 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
36 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
28 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
54 ms |
900 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
10 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
19 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
27 ms |
616 KB |
Correct! Azusa and Laika like the garden :) |
14 |
Correct |
24 ms |
660 KB |
Correct! Azusa and Laika like the garden :) |
15 |
Correct |
30 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
16 |
Correct |
31 ms |
688 KB |
Correct! Azusa and Laika like the garden :) |
17 |
Correct |
35 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
856 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
13 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
652 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
11 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
13 ms |
820 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
60 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
77 ms |
992 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
59 ms |
1104 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
83 ms |
816 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
76 ms |
1160 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
70 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
72 ms |
1080 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
53 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
14 |
Correct |
63 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
15 |
Correct |
64 ms |
852 KB |
Correct! Azusa and Laika like the garden :) |
16 |
Correct |
70 ms |
728 KB |
Correct! Azusa and Laika like the garden :) |
17 |
Correct |
66 ms |
944 KB |
Correct! Azusa and Laika like the garden :) |
18 |
Correct |
73 ms |
976 KB |
Correct! Azusa and Laika like the garden :) |
19 |
Correct |
30 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
20 |
Correct |
39 ms |
704 KB |
Correct! Azusa and Laika like the garden :) |
21 |
Correct |
19 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
22 |
Correct |
43 ms |
780 KB |
Correct! Azusa and Laika like the garden :) |
23 |
Correct |
38 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
24 |
Correct |
19 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
25 |
Correct |
40 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
26 |
Correct |
36 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
27 |
Correct |
28 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
28 |
Correct |
54 ms |
900 KB |
Correct! Azusa and Laika like the garden :) |
29 |
Correct |
10 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
30 |
Correct |
19 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
31 |
Correct |
27 ms |
616 KB |
Correct! Azusa and Laika like the garden :) |
32 |
Correct |
24 ms |
660 KB |
Correct! Azusa and Laika like the garden :) |
33 |
Correct |
30 ms |
604 KB |
Correct! Azusa and Laika like the garden :) |
34 |
Correct |
31 ms |
688 KB |
Correct! Azusa and Laika like the garden :) |
35 |
Correct |
35 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
36 |
Correct |
79 ms |
1160 KB |
Correct! Azusa and Laika like the garden :) |
37 |
Correct |
144 ms |
1820 KB |
Correct! Azusa and Laika like the garden :) |
38 |
Correct |
98 ms |
852 KB |
Correct! Azusa and Laika like the garden :) |
39 |
Correct |
80 ms |
1104 KB |
Correct! Azusa and Laika like the garden :) |
40 |
Correct |
96 ms |
1108 KB |
Correct! Azusa and Laika like the garden :) |
41 |
Correct |
113 ms |
1156 KB |
Correct! Azusa and Laika like the garden :) |
42 |
Correct |
115 ms |
1044 KB |
Correct! Azusa and Laika like the garden :) |
43 |
Correct |
83 ms |
1108 KB |
Correct! Azusa and Laika like the garden :) |
44 |
Correct |
80 ms |
1136 KB |
Correct! Azusa and Laika like the garden :) |
45 |
Correct |
112 ms |
1136 KB |
Correct! Azusa and Laika like the garden :) |
46 |
Correct |
90 ms |
1112 KB |
Correct! Azusa and Laika like the garden :) |
47 |
Correct |
134 ms |
1828 KB |
Correct! Azusa and Laika like the garden :) |
48 |
Correct |
87 ms |
1040 KB |
Correct! Azusa and Laika like the garden :) |
49 |
Correct |
107 ms |
956 KB |
Correct! Azusa and Laika like the garden :) |
50 |
Correct |
94 ms |
1104 KB |
Correct! Azusa and Laika like the garden :) |
51 |
Correct |
97 ms |
1580 KB |
Correct! Azusa and Laika like the garden :) |
52 |
Correct |
93 ms |
1104 KB |
Correct! Azusa and Laika like the garden :) |
53 |
Correct |
74 ms |
1104 KB |
Correct! Azusa and Laika like the garden :) |
54 |
Correct |
90 ms |
1104 KB |
Correct! Azusa and Laika like the garden :) |
55 |
Correct |
92 ms |
1184 KB |
Correct! Azusa and Laika like the garden :) |
56 |
Correct |
116 ms |
1192 KB |
Correct! Azusa and Laika like the garden :) |
57 |
Correct |
110 ms |
1108 KB |
Correct! Azusa and Laika like the garden :) |
58 |
Correct |
116 ms |
1748 KB |
Correct! Azusa and Laika like the garden :) |
59 |
Correct |
109 ms |
1108 KB |
Correct! Azusa and Laika like the garden :) |
60 |
Correct |
102 ms |
1108 KB |
Correct! Azusa and Laika like the garden :) |