#include <stdio.h>
#define NM 200000
int max(int a, int b) { return a > b ? a : b; }
int check(int n, int m, int k) {
if (n % 2 != 0 || m % 2 != 0 || k > n * m / 4 || k < max(n, m) / 2)
return 0;
if (k == n * m / 4 - 1)
return 0;
if (n == m && k == n / 2 + 1)
return 0;
return 1;
}
int aa[NM], n_, m_, a_;
void solve(int n, int m, int k, int i_, int j_) {
int n1, n2, m1, m2, l1, r1, l2, r2, k1, k2, i, j;
if (n == 2) {
for (i = 0, j = 0; j < m; j += 2) {
aa[(i_ + i) * m_ + (j_ + j)] = aa[(i_ + i) * m_ + (j_ + j + 1)] = a_;
aa[(i_ + i + 1) * m_ + (j_ + j)] = aa[(i_ + i + 1) * m_ + (j_ + j + 1)] = a_;
a_++;
}
} else if (m == 2) {
for (i = 0, j = 0; i < n; i += 2) {
aa[(i_ + i) * m_ + (j_ + j)] = aa[(i_ + i) * m_ + (j_ + j + 1)] = a_;
aa[(i_ + i + 1) * m_ + (j_ + j)] = aa[(i_ + i + 1) * m_ + (j_ + j + 1)] = a_;
a_++;
}
} else if (check(n - 2, m - 2, k - 1)) {
solve(n - 2, m - 2, k - 1, i_ + 1, j_ + 1);
for (i = 0; i < n; i++)
aa[(i_ + i) * m_ + (j_ + 0)] = aa[(i_ + i) * m_ + (j_ + m - 1)] = a_;
for (j = 0; j < m; j++)
aa[(i_ + 0) * m_ + (j_ + j)] = aa[(i_ + n - 1) * m_ + (j_ + j)] = a_;
a_++;
} else {
for (n1 = 2; n1 <= n; n1 += 2) {
n2 = n - n1, l1 = max(n1, m) / 2, r1 = n1 * m / 4, l2 = max(n2, m) / 2, r2 = n2 * m / 4;
for (k1 = max(l1, k - r2); k1 <= r1 && (k2 = k - k1) >= l2; k1++)
if (check(n1, m, k1) && check(n2, m, k2)) {
solve(n1, m, k1, i_, j_);
solve(n2, m, k2, n1 + i_, j_);
return;
}
}
for (m1 = 2; m1 <= m; m1 += 2) {
m2 = m - m1, l1 = max(n, m1) / 2, r1 = n * m1 / 4, l2 = max(n, m2) / 2, r2 = n * m2 / 4;
for (k1 = max(l1, k - r2); k1 <= r1 && (k2 = k - k1) >= l2; k1++)
if (check(n, m1, k1) && check(n, m2, k2)) {
solve(n, m1, k1, i_, j_);
solve(n, m2, k2, i_, m1 + j_);
return;
}
}
}
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m, k, i, j;
scanf("%d%d%d", &n, &m, &k), n_ = n, m_ = m;
if (!check(n, m, k))
printf("NO\n");
else {
a_ = 1, solve(n, m, k, 0, 0);
printf("YES\n");
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++)
printf("%d ", aa[i * m + j]);
printf("\n");
}
}
}
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:66:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
Main.c:70:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d%d%d", &n, &m, &k), n_ = n, m_ = m;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
9 ms |
528 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
9 ms |
528 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
9 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
9 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
7 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
7 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
10 ms |
544 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
7 ms |
556 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
8 ms |
628 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
7 ms |
544 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
7 ms |
648 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
7 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
3 ms |
352 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
4 ms |
468 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
4 ms |
468 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
4 ms |
436 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
6 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
4 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
14 |
Correct |
4 ms |
412 KB |
Correct! Azusa and Laika like the garden :) |
15 |
Correct |
5 ms |
428 KB |
Correct! Azusa and Laika like the garden :) |
16 |
Correct |
5 ms |
412 KB |
Correct! Azusa and Laika like the garden :) |
17 |
Correct |
3 ms |
436 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
9 ms |
528 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
9 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
9 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
7 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
7 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
10 ms |
544 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
7 ms |
556 KB |
Correct! Azusa and Laika like the garden :) |
14 |
Correct |
8 ms |
628 KB |
Correct! Azusa and Laika like the garden :) |
15 |
Correct |
8 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
16 |
Correct |
7 ms |
544 KB |
Correct! Azusa and Laika like the garden :) |
17 |
Correct |
7 ms |
648 KB |
Correct! Azusa and Laika like the garden :) |
18 |
Correct |
7 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
19 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
20 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
21 |
Correct |
3 ms |
352 KB |
Correct! Azusa and Laika like the garden :) |
22 |
Correct |
4 ms |
468 KB |
Correct! Azusa and Laika like the garden :) |
23 |
Correct |
4 ms |
468 KB |
Correct! Azusa and Laika like the garden :) |
24 |
Correct |
4 ms |
436 KB |
Correct! Azusa and Laika like the garden :) |
25 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
26 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
27 |
Correct |
6 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
28 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
29 |
Correct |
4 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
30 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
31 |
Correct |
3 ms |
340 KB |
Correct! Azusa and Laika like the garden :) |
32 |
Correct |
4 ms |
412 KB |
Correct! Azusa and Laika like the garden :) |
33 |
Correct |
5 ms |
428 KB |
Correct! Azusa and Laika like the garden :) |
34 |
Correct |
5 ms |
412 KB |
Correct! Azusa and Laika like the garden :) |
35 |
Correct |
3 ms |
436 KB |
Correct! Azusa and Laika like the garden :) |
36 |
Correct |
11 ms |
788 KB |
Correct! Azusa and Laika like the garden :) |
37 |
Correct |
10 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
38 |
Correct |
11 ms |
788 KB |
Correct! Azusa and Laika like the garden :) |
39 |
Correct |
11 ms |
852 KB |
Correct! Azusa and Laika like the garden :) |
40 |
Correct |
15 ms |
804 KB |
Correct! Azusa and Laika like the garden :) |
41 |
Correct |
12 ms |
784 KB |
Correct! Azusa and Laika like the garden :) |
42 |
Correct |
17 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
43 |
Correct |
12 ms |
800 KB |
Correct! Azusa and Laika like the garden :) |
44 |
Correct |
11 ms |
788 KB |
Correct! Azusa and Laika like the garden :) |
45 |
Correct |
10 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
46 |
Correct |
11 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
47 |
Correct |
11 ms |
784 KB |
Correct! Azusa and Laika like the garden :) |
48 |
Correct |
11 ms |
796 KB |
Correct! Azusa and Laika like the garden :) |
49 |
Correct |
12 ms |
748 KB |
Correct! Azusa and Laika like the garden :) |
50 |
Correct |
11 ms |
744 KB |
Correct! Azusa and Laika like the garden :) |
51 |
Correct |
12 ms |
756 KB |
Correct! Azusa and Laika like the garden :) |
52 |
Correct |
11 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
53 |
Correct |
11 ms |
812 KB |
Correct! Azusa and Laika like the garden :) |
54 |
Correct |
11 ms |
812 KB |
Correct! Azusa and Laika like the garden :) |
55 |
Correct |
11 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
56 |
Correct |
20 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
57 |
Correct |
11 ms |
804 KB |
Correct! Azusa and Laika like the garden :) |
58 |
Correct |
13 ms |
820 KB |
Correct! Azusa and Laika like the garden :) |
59 |
Correct |
11 ms |
784 KB |
Correct! Azusa and Laika like the garden :) |
60 |
Correct |
11 ms |
800 KB |
Correct! Azusa and Laika like the garden :) |