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>
using namespace std;
#define f(i,a,b) for(int i = a; i < b; i++)
bool fe;
int c;
pair<int,int> range(int n, int m){
if(n == 2) return {m/2, m/2};
return {n*m/4 - m/2, n*m/4};
}
void print(vector <vector<int>> v){
int n = v.size(), m = v[0].size();
if(!fe){
f(i,0,n) { f(j,0,m) cout << ((v[i][j] == 0) ? c : v[i][j]) << " "; cout << "\n"; }
}
else{
f(i,0,m) { f(j,0,n) cout << ((v[j][i] == 0) ? c : v[j][i]) << " "; cout << "\n"; }
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t; cin >> t;
while(t--){
int n, m, k;
cin >> n >> m >> k;
if(n&1 or m&1){
cout << "NO\n";
continue;
}
fe = 0;
if(n > m) {
fe = 1;
swap(n, m);
}
vector <vector<int>> v(n, vector <int> (m));
bool ra = 0;
int ni = n, mi = m;
int xi = 0, yi = 0;
c = 1;
while(1){
pair<int,int> p = range(ni, mi);
if(p.second < k or k < p.first){
f(i,xi,xi+ni){
v[i][yi] = v[i][yi + mi - 1] = c;
}
f(i,yi,yi+mi){
v[xi][i] = v[xi + ni - 1][i] = c;
}
c++, k--;
xi++, yi++;
ni -= 2, mi -= 2;
if(ni == 0){
ra = 1;
cout << "NO\n";
break;
}
}
else break;
}
if(ra) continue;
if(ni == 2){
for(int i = yi; i < yi+mi-1; i += 2){
v[xi][i] = v[xi][i+1] = c;
v[xi+1][i] = v[xi+1][i+1] = c;
c++;
}
}
else{
for(int i = xi; i < xi+ni-4; i += 2){
for(int j = yi; j < yi+mi-1; j += 2){
v[i][j] = v[i][j+1] = c;
v[i+1][j] = v[i+1][j+1] = c;
c++;
k--;
}
}
int L = 2*k - mi;
if(mi - L < 4 and mi - L > 0){
cout << "NO\n";
ra = 1;
}
int e = xi + ni - 1;
for(int i = yi; i < yi+L-1; i += 2){
v[e-3][i] = v[e-3][i+1] = c;
v[e-2][i] = v[e-2][i+1] = c;
c++;
v[e-1][i] = v[e-1][i+1] = c;
v[e][i] = v[e][i+1] = c;
c++;
}
for(int i = yi+L+1; i < yi+mi-1; i += 2){
v[e-2][i] = v[e-2][i+1] = c;
v[e-1][i] = v[e-1][i+1] = c;
c++;
}
}
if(!ra){
cout << "YES\n";
print(v);
}
}
return 0;
}
# | 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... |