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 ll long long
#define fast1 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define int long long
#define mod 1000000007
#define pii pair<int,int>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,avx")
#pragma GCC optimize("unroll-loops")
int n,m,k;
int dizi[5][50005];
void solve()
{
cin>>n>>m>>k;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
dizi[i][j]=0;
if(n%2!=0||m%2==1)
{
cout<<"NO"<<endl;
return;
}
if(k>n*m/4)
{
cout<<"NO"<<endl;
return;
}
if(k==(n*m)/4)
{
int cnt=1;
for(int i=0;i<n;i+=2)
{
for(int j=0;j<m;j+=2)
{
dizi[i][j]=cnt;
dizi[i+1][j]=cnt;
dizi[i+1][j+1]=cnt;
dizi[i][j+1]=cnt;
cnt++;
}
}
}
else if(n==2||m==2)
{
cout<<"NO"<<endl;
return;
}
else if(k==(n*m)/4-1||k<m/2)
{
cout<<"NO"<<endl;
return;
}
else
{
int cnt=1;
int bak=0;
for(int i=0;i<n;i+=2)
for(int j=0;j<k-(m/2);j++)
{
bak=j*2;
dizi[i][bak]=cnt;
dizi[i+1][bak]=cnt;
dizi[i+1][bak+1]=cnt;
dizi[i][bak+1]=cnt;
cnt++;
}
for(int j=(k-(m/2))*2+1;j<m-1;j+=2)
for(int i=1;i<n-1;i+=2)
{
dizi[i][j]=cnt;
dizi[i+1][j]=cnt;
dizi[i+1][j+1]=cnt;
dizi[i][j+1]=cnt;
cnt++;
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(dizi[i][j]==0)
dizi[i][j]=cnt;
}
cout<<"YES"<<endl;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cout<<dizi[i][j]<<" ";
cout<<endl;
}
}
signed main()
{
fast1
int t;
cin>>t;
while(t--)
solve();
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... |