제출 #1347182

#제출 시각아이디문제언어결과실행 시간메모리
1347182MunkhErdeneGardening (RMI21_gardening)C++17
0 / 100
9 ms916 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define _ << " " <<
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ull unsigned long long
#define lll __int128
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define BlueCrowner ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
const ll mod = 1e9 + 7;
const ll mod1 = 998244353;
const ll naim = 1e9;
const ll max_bit = 60;
const ull tom = ULLONG_MAX;
const ll MAXN = 100005;
const ll LOG = 20;
const ll NAIM = 1e18;
const ll N = 2e6 + 5;
// ---------- GCD ----------
ll gcd(ll a, ll b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}
// ---------- LCM ----------
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
// ---------- Modular Exponentiation ----------
ll modpow(ll a, ll b, ll m = mod) {
	ll c = 1;
	a %= m;
	while (b > 0) {
		if (b & 1) c = c * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return c;
}
// ---------- Modular Inverse (Fermat’s Little Theorem) ----------
ll modinv(ll a, ll m = mod) {
	return modpow(a, m - 2, m);
}
// ---------- Factorials and Inverse Factorials ----------
ll fact[N], invfact[N];
void pre_fact(ll n = N-1, ll m = mod) {
	fact[0] = 1;
	for (ll i = 1; i <= n; i++) fact[i] = fact[i-1] * i % m;
	invfact[n] = modinv(fact[n], m);
	for (ll i = n; i > 0; i--) invfact[i-1] = invfact[i] * i % m;
}
// ---------- nCr ----------
ll nCr(ll n, ll r, ll m = mod) {
	if (r < 0 || r > n) return 0;
	return fact[n] * invfact[r] % m * invfact[n-r] % m;
}
// ---------- Sieve of Eratosthenes ----------
vector<ll> primes;
bool is_prime[N];
void sieve(ll n = N-1) {
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (ll i = 2; i * i <= n; i++) {
		if (is_prime[i]) {
			for (ll j = i * i; j <= n; j += i)
				is_prime[j] = false;
		}
	}
	for (ll i = 2; i <= n; i++)
		if (is_prime[i]) primes.pb(i);
}
void solve() {
	ll n, m, k; cin >> n >> m >> k;
	bool t = 0;
	if(n > m) {
		swap(n, m);
		t = 1;
	}
	if(n & 1 || m & 1) {
		no;
		return;
	}
	ll lowerbound = n / 2;
	ll upperbound = (n / 2) * (m / 2);
	if(k < lowerbound || k > upperbound) {
		no;
		return;
	}
	vector<vector<ll>> ans(n, vector<ll> (m));
	ll cur = 0;
	for(ll i = 0 ; i < n; i += 2) {
		for(ll j = 0; j < m; j += 2) {
			ans[i][j] = ans[i + 1][j] = ans[i][j + 1] = ans[i + 1][j + 1] = ++cur;
		}
	}
	
	for(ll i = 0 ; i < n; i += 2) {
		for(ll j = 2; j < m; j += 2) {
			if(cur > k) {
				ans[i][j] = ans[i + 1][j] = ans[i][j + 1] = ans[i + 1][j + 1] = ans[i][0];
				cur--;
			}
		}
	}
	if(t) {
		vector<vector<ll>> ansT(m, vector<ll> (n));
		FOR(i, 0, m) {
			FOR(j, 0, n) {
				ansT[i][j] = ans[j][i];
			}
		}
		swap(n, m);
		swap(ans, ansT);
	}
	vector<ll> nums;
	FOR(i, 0, n) {
		FOR(j, 0, m) nums.pb(ans[i][j]);
	}
	sort(all(nums));
	nums.erase(unique(all(nums)), nums.end());
	yes;
	FOR(i, 0, n) {
		FOR(j, 0, m) cout << upper_bound(all(nums), ans[i][j]) - nums.begin() << ' '; cout << '\n';
	}
}
int main() {
	BlueCrowner;
	ll t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...