#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <iomanip>
#include <cassert>
#include <deque>
#include <functional>
#include <set>
#include <queue>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <complex>
using namespace std;
int gcd(int a, int b) {
if (!b) {
return a;
}
return gcd(b, a % b);
}
int32_t main() {
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
if (n % 2 == 1 || m % 2 == 1) {
cout << "NO" << '\n';
} else {
bool ok = false;
int c = 0;
for (int borderL = 0; borderL < min(n, m) / 2; borderL += 2) {
for (int borderLen = 0; borderLen < min(n, m) - borderL; ++borderLen) {
int borderR = borderL + borderLen;
int side1 = n - borderL * 2;
int side2 = m - borderL * 2;
int s1 = n - borderR * 2;
int s2 = m - borderR * 2;
int inside = s1 * s2;
int cnt = borderLen + (n * m - side1 * side2 + inside) / 4;
if (cnt == k) {
vector<vector<int>> matr(n, vector<int> (m, 0));
for (int i = borderL; i < borderR; ++i) {
++c;
for (int j = i; j < m - i; ++j) {
matr[i][j] = c;
matr[n - i - 1][j] = c;
}
for (int j = i; j < n - i; ++j) {
matr[j][i] = c;
matr[j][m - i - 1] = c;
}
}
for (int x = borderR; x < n - borderR; x += 2) {
for (int y = borderR; y < m - borderR; y += 2) {
matr[x][y] = matr[x + 1][y] = matr[x][y + 1] = matr[x + 1][y + 1] = ++c;
}
}
for (int x = 0; x < borderL; x += 2) {
for (int y = 0; y < m; y += 2) {
matr[x][y] = matr[x + 1][y] = matr[x][y + 1] = matr[x + 1][y + 1] = ++c;
}
}
for (int x = n - borderL; x < n; x += 2) {
for (int y = 0; y < m; y += 2) {
matr[x][y] = matr[x + 1][y] = matr[x][y + 1] = matr[x + 1][y + 1] = ++c;
}
}
for (int x = borderL; x < n - borderL; x += 2) {
for (int y = 0; y < borderL; y += 2) {
matr[x][y] = matr[x + 1][y] = matr[x][y + 1] = matr[x + 1][y + 1] = ++c;
}
}
for (int x = borderL; x < n - borderL; x += 2) {
for (int y = m - borderL; y < m; y += 2) {
matr[x][y] = matr[x + 1][y] = matr[x][y + 1] = matr[x + 1][y + 1] = ++c;
}
}
cout << "YES\n";
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cout << matr[i][j] << ' ';
}
cout << '\n';
}
ok = true;
break;
}
}
if (ok) {
break;
}
}
if (!ok) {
cout << "NO\n";
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
69 ms |
720 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
69 ms |
720 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
69 ms |
720 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
4 ms |
340 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
2 ms |
340 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
69 ms |
720 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |