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 forn(i,n) for (int i=0;i<n;++i)
#define prn {cout<<"NO\n";return;}
#define pry cout<<"YES\n";
void f(int n, int m, int k, int depth) {
int l=((n+2)/4)*(m/2), r=(n/2)*(m/2);
if (k-depth>r) prn;
if (n==0) prn;
int x=k-depth;
//cout<<"F "<<n<<' '<<k<<' '<<depth<<' '<<l<<' '<<r<<' '<<x<<'\n';
//int c; cin>>c;
//if (c==-1) return;
if (l<=x && x<=r && (x!=(r-1))) {
pry;
int y=(n/2)*(m/2)-x;
vector<vector<int>> a(n+2*depth,vector<int>(m+2*depth,1));
for (int i=0; i<depth; ++i) {
for (int j=i; j<m+2*depth; ++j) a[i][j]=a[n+2*depth-1-i][j]=i+1;
for (int j=i; j<n+2*depth; ++j) a[j][i]=a[j][m+2*depth-1-i]=i+1;
}
int col=depth+1;
int last=depth;
for (int i=0; i+3<n; i+=4) {
int need=min(2*y,m);
for (int j=0; j<need; ++j) a[depth+i][depth+j]=a[depth+i+3][depth+j]=col;
a[depth+i+1][depth]=a[depth+i+2][depth]=a[depth+i+1][depth+need-1]=a[depth+i+2][depth+need-1]=col;
col++;
for (int j=1; j<need-1; j+=2) {
a[depth+i+1][depth+j]=a[depth+i+2][depth+j]=a[depth+i+1][depth+j+1]=a[depth+i+2][depth+j+1]=col;
col++;
}
y-=need/2;
for (int j=need; j<m; ++j) {
a[depth+i][depth+j]=a[depth+i][depth+j+1]=a[depth+i+1][depth+j]=a[depth+i+1][depth+j+1]=col++;
a[depth+i+2][depth+j]=a[depth+i+2][depth+j+1]=a[depth+i+3][depth+j]=a[depth+i+3][depth+j+1]=col++;
}
last=i+4;
}
if ((n%4)==2)
for (int j=0; j<m; j+=2) {
a[depth+last][depth+j]=a[depth+last][depth+j+1]=a[depth+last+1][depth+j]=a[depth+last+1][depth+j+1]=col++;
}
for (auto p:a) {
for (auto v:p) cout<<v<<' ' ;cout<<'\n';
}
return;
}
f(n-2,m-2,k,depth+1);
}
void solve() {
int n,m,k; cin>>n>>m>>k;
int s=n*m;
if (k>(s/4)) prn;
if (n&1 || m&1) prn;
vector<vector<int>> a(n,vector<int>(m,-1));
if (n==2) {
if (k!=m/2) prn;
pry;
forn(k,2) {
for (int i=0; i<m; i+=2) {
cout<<(i/2)+1<<' '<<(i/2)+1<<' ';
}
cout<<'\n';
}
return;
}
if (n==4) {
if (k<(m/2) || k>m) prn;
if (k==m-1) prn;
pry;
int y=m-k;
assert(y!=1);
if (y) {
a[1][0]=a[2][0]=1;
a[1][2*y-1]=a[2][2*y-1]=1;
}
int cnt=(y>0)+1;
for (int i=0; i<2*y; ++i) {
a[0][i]=a[3][i]=1;
}
for (int j=1; j<2*y-1; j+=2) {
a[1][j]=a[1][j+1]=a[2][j]=a[2][j+1]=cnt++;
}
for (int i=2*y; i<m; i+=2) {
a[0][i]=a[0][i+1]=a[1][i]=a[1][i+1]=cnt++;
a[2][i]=a[2][i+1]=a[3][i]=a[3][i+1]=cnt++;
}
for (auto x:a) {
for (auto y:x) cout<<y<<' ';
cout<<'\n';
}
return;
}
if (m==4) {
swap(m,n);
a.assign(n,vector<int>(m,-1));
if (k<(m/2) || k>m) prn;
if (k==m-1) prn;
pry;
int y=m-k;
assert(y!=1);
if (y) {
a[1][0]=a[2][0]=1;
a[1][2*y-1]=a[2][2*y-1]=1;
}
int cnt=(y>0)+1;
for (int i=0; i<2*y; ++i) {
a[0][i]=a[3][i]=1;
}
for (int j=1; j<2*y-1; j+=2) {
a[1][j]=a[1][j+1]=a[2][j]=a[2][j+1]=cnt++;
}
for (int i=2*y; i<m; i+=2) {
a[0][i]=a[0][i+1]=a[1][i]=a[1][i+1]=cnt++;
a[2][i]=a[2][i+1]=a[3][i]=a[3][i+1]=cnt++;
}
swap(n,m);
for (int i=0; i<n; ++i) {
for (int j=0; j<m; ++j) {
cout<<a[j][i]<<' ';
}
cout<<'\n';
}
return;
}
if (m==2) {
swap(n,m);
if (k!=m/2) prn;
pry;
for (int i=0; i<m; i+=2) {
forn(k,2) cout<<(i/2)+1<<' '<<(i/2)+1<<'\n';
}
return;
}
if (n==m) {
f(n,m,k,0);
}
}
int32_t main() {
//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t; cin>>t;
while (t--) solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void f(int, int, int, int)':
Main.cpp:50:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
50 | for (auto v:p) cout<<v<<' ' ;cout<<'\n';
| ^~~
Main.cpp:50:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
50 | for (auto v:p) cout<<v<<' ' ;cout<<'\n';
| ^~~~
# | 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... |