#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[200000];
void solve(){
int N, M, K; cin >> N >> M >> K;
if(N % 2 == 1 || M % 2 == 1 || K > N * M / 4 || K < max(N, M) / 2 || K == N * M / 4 - 1) {
cout << "NO" << endl;
return;
}
if(N == 2){
if(K != M / 2){
cout << "NO" << endl;
}else{
cout << "YES" << endl;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
cout << j / 2 + 1 << ' ';
}
cout << endl;
}
}
return;
}
if(M == 2){
if(K != N / 2){
cout << "NO" << endl;
}else{
cout << "YES" << endl;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
cout << i / 2 + 1 << ' ';
}
cout << endl;
}
}
return;
}
cout << "YES" << endl;
int x1 = 0, x2 = N - 1, y1 = 0, y2 = M - 1;
while(K > 0){
// cout << x2 - x1 + 1 << ' ' << y2 - y1 + 1 << ' ' << K - (x2 - x1 + 1) / 2 << ' ' << max(x2 - x1 + 1, y2 - y1 - 1) << endl;
if(x2 - x1 + 1 >= 6 && y2 - y1 + 1 >= 6 && K - 1 <= (x2 - x1 - 1) * (y2 - y1 - 1) / 4 || x2 - x1 + 1 >= 4 && y2 - y1 + 1 >= 4 && K - 1 == (x2 - x1 - 1) * (y2 - y1 - 1) / 4){
for(int x = x1; x <= x2; x++){
a[x * M + y1] = a[x * M + y2] = K;
}
for(int y = y1; y <= y2; y++){
a[x1 * M + y] = a[x2 * M + y] = K;
}
K--; x1++; x2--; y1++; y2--;
}else if(x2 - x1 + 1 >= 6 && x2 - x1 + 1 >= y2 - y1 + 1 && K - (y2 - y1 + 1) / 2 >= max(x2 - x1 - 1, y2 - y1 + 1) / 2){
for(int y = y1; y <= y2; y++){
a[x1 * M + y] = a[(x1 + 1) * M + y] = K - (y - y1) / 2;
}
K -= (y2 - y1 + 1) / 2; x1 += 2;
}else if(y2 - y1 + 1 >= 6 && y2 - y1 + 1 >= x2 - x1 + 1 && K - (x2 - x1 + 1) / 2 >= max(x2 - x1 + 1, y2 - y1 - 1) / 2){
for(int x = x1; x <= x2; x++){
a[x * M + y1] = a[x * M + (y1 + 1)] = K - (x - x1) / 2;
}
K -= (x2 - x1 + 1) / 2; y1 += 2;
}else if(x2 - x1 + 1 == 4 && y2 - y1 + 1 == 4){
if(K == 4){
for(int x = x1; x <= x2; x++){
for(int y = y1; y <= y2; y++){
a[x * M + y] = (x - x1) / 2 * 2 + (y - y1) / 2 + 1;
}
}
K -= 4;
}else if(K == 2){
for(int x = x1; x <= x2; x++){
for(int y = y1; y <= y2; y++){
a[x * M + y] = 1;
}
}
for(int x = x1 + 1; x <= x2 - 1; x++){
for(int y = y1 + 1; y <= y2 - 1; y++){
a[x * M + y] = 2;
}
}
K -= 2;
}else{
assert(1 == 0);
}
}else if(x2 - x1 + 1 == 2){
assert(K == (y2 - y1 + 1) / 2);
for(int y = y1; y <= y2; y++){
a[x1 * M + y] = (y - y1) / 2 + 1;
a[(x1 + 1) * M + y] = (y - y1) / 2 + 1;
}
K -= (y2 - y1 + 1);
}else if(y2 - y1 + 1 == 2){
assert(K == (x2 - x1 + 1) / 2);
for(int x = x1; x <= x2; x++){
a[x * M + y1] = (x - x1) / 2 + 1;
a[x * M + y1 + 1] = (x - x1) / 2 + 1;
}
K -= (x2 - x1 + 1);
}
}
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
cout << a[i * M + j] << ' ';
}
cout << endl;
}
}
int32_t main(){
int T; cin >> T;
while(T--){
solve();
}
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:46:49: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
46 | if(x2 - x1 + 1 >= 6 && y2 - y1 + 1 >= 6 && K - 1 <= (x2 - x1 - 1) * (y2 - y1 - 1) / 4 || x2 - x1 + 1 >= 4 && y2 - y1 + 1 >= 4 && K - 1 == (x2 - x1 - 1) * (y2 - y1 - 1) / 4){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
640 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
640 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
21 ms |
560 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
21 ms |
616 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
640 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
21 ms |
560 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
21 ms |
616 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Runtime error |
1 ms |
424 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
640 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
21 ms |
560 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
21 ms |
616 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Runtime error |
1 ms |
424 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |