This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 200005
using namespace std;
void solve(){
int n,m,k;
cin >> n >> m >> k;
if(n % 2 || m % 2 || n*m/4 < k || k < min(n,m)/2){
cout << "NO" << "\n";
return;
}
cout << "YES" << "\n";
vector<vector<int>> ans(n,vector<int>(m,0));
if(n <= m){
int dec = n*m/4 - k;
int last = 0;
for(int i = 0;i<n;i+=2){
int now = m/2;
int del = min(dec,now-1);
now -= del;
dec -= del;
for(int j = 0;j<2*now;j++){
last++;
int r = j + 1;
if(j == 2*(now-1))r = m-1;
for(int c = j;c<=r;c++){
ans[i][c] = ans[i+1][c] = last;
}
j = r;
}
}
}
else{//m < n
int dec = n*m/4 - k;
int last = 0;
for(int i = 0;i<m;i+=2){
int now = n/2;
int del = min(dec,now-1);
now -= del;
dec -= del;
for(int j = 0;j<2*now;j++){
last++;
int r = j + 1;
if(j == 2*(now-1))r = n-1;
for(int c = j;c<=r;c++){
ans[c][i] = ans[c][i+1] = last;
}
j = r;
}
}
}
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
cout << ans[i][j] << " ";
}
cout << "\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |