// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;
int t;
int n, m;
ll k;
vi g[MAXN];
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> t;
while (t--) {
cin >> n >> m >> k;
if ((n & 1) || (m & 1)) {
cout << "NO\n";
continue;
}
if (n == 2) {
if (k != m / 2) {
cout << "NO\n";
} else {
cout << "YES\n";
REP (i, 0, n) {
REP (j, 0, m) {
cout << j / 2 + 1 << ' ';
}
cout << '\n';
}
}
continue;
}
if (m == 2) {
if (k != n / 2) {
cout << "NO\n";
} else {
cout << "YES\n";
REP (i, 0, n) {
REP (j, 0, m) {
cout << i / 2 + 1 << ' ';
}
cout << '\n';
}
}
continue;
}
if (n == 4 && m == 4) {
if (k == 4) {
cout << "YES\n";
REP (i, 0, n) {
REP (j, 0, m) {
cout << i / 2 + j / 2 * 2 + 1 << ' ';
}
cout << '\n';
}
} else if (k == 2) {
cout << "YES\n";
REP (i, 0, n) {
REP (j, 0, m) {
g[i][j] = 1;
}
}
REP (i, 1, 3) {
REP (j, 1, 3) {
g[i][j] = 2;
}
}
REP (i, 1, n + 1) {
REP (j, 1, n + 1) {
cout << g[i][j] << ' ';
}
cout << '\n';
}
} else {
cout << "NO\n";
}
continue;
}
ll mn = n / 2, mx = (ll) (n / 2) * (n / 2);
if (k < mn || k > mx) {
cout << "NO\n";
continue;
}
if (k == mn + 1 || k == mx - 1) {
cout << "NO\n";
continue;
}
cout << "YES\n";
REP (i, 1, n + 1) {
g[i] = vi(m + 1);
}
int rt = -1;
RREP (i, n / 2, 1) {
if ((ll) i * i + n / 2 - i <= k) {
rt = i;
break;
}
}
assert(rt != -1);
int ptr = 1;
if ((ll) (rt + 1) * (rt + 1) + n / 2 - rt - 2 == k) {
RREP (k, n / 2, rt + 2) {
for (int i : {ptr, n - ptr + 1}) {
REP (j, ptr, m - ptr + 2) {
g[i][j] = ptr;
}
}
REP (i, ptr, n - ptr + 2) {
for (int j : {ptr, m - ptr + 1}) {
g[i][j] = ptr;
}
}
ptr++;
}
REP (i, ptr, n - ptr + 2) {
g[i][ptr + 1] = ptr - 1;
}
int optr = ptr;
for (int i = optr - 1; i <= n - optr + 1; i += 2) {
REP (a, 0, 2) {
REP (b, 0, 2) {
g[i + a][optr - 1 + b] = ptr;
}
}
ptr++;
}
for (int i = optr; i <= n - optr + 1; i += 2) {
for (int j = optr + 2; j <= m - optr + 1; j += 2) {
if (i - 4 < optr && j + 4 > m - optr + 1) {
continue;
}
REP (a, 0, 2) {
REP (b, 0, 2) {
g[i + a][j + b] = ptr;
}
}
ptr++;
}
}
REP (i, optr, optr + 4) {
RREP (j, m - optr + 1, m - optr - 2) {
g[i][j] = ptr;
}
}
ptr++;
REP (i, optr + 1, optr + 3) {
RREP (j, m - optr, m - optr - 1) {
g[i][j] = ptr;
}
}
ptr++;
} else {
ll need = k - ((ll) rt * rt + n / 2 - rt);
RREP (k, n / 2, rt + 1) {
for (int i : {ptr, n - ptr + 1}) {
REP (j, ptr, m - ptr + 2) {
g[i][j] = ptr;
}
}
REP (i, ptr, n - ptr + 2) {
for (int j : {ptr, m - ptr + 1}) {
g[i][j] = ptr;
}
}
ptr++;
}
int optr = ptr;
int lft = m - optr - 1;
if (need < rt) {
lft = optr + need * 2 - 1;
}
for (int i = optr - 1; i <= n - optr + 2; i += 2) {
for (int j = optr - 1; j < lft; j += 2) {
REP (a, 0, 2) {
REP (b, 0, 2) {
g[i + a][j + b] = ptr;
}
}
ptr++;
}
}
REP (i, optr, n - optr + 2) {
g[i][lft] = optr - 1;
}
need = max(0ll, need - rt + 1);
cerr << optr << '\n';
for (int i = n - optr + 1; i > n - optr + 1 - 2 * need; i -= 2) {
for (int j = lft; j <= n - optr + 1; j += 2) {
REP (a, 0, 2) {
REP (b, 0, 2) {
g[i + a][j + b] = ptr;
}
}
ptr++;
}
REP (j, lft, n - optr + 3) {
g[i - 1][j] = optr - 1;
}
}
for (int i = optr; i <= n - optr + 1 - 2 * need; i += 2) {
for (int j = lft + 1; j <= n - optr; j += 2) {
REP (a, 0, 2) {
REP (b, 0, 2) {
g[i + a][j + b] = ptr;
}
}
ptr++;
}
}
}
REP (i, 1, n + 1) {
REP (j, 1, n + 1) {
cout << setfill(' ') << setw(2) << g[i][j] << ' ';
}
cout << '\n';
}
assert(ptr - 1 == k);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
9940 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
9940 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
9940 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
10068 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
9940 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
9940 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |