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 ll long long
void draw(ll n,ll m,ll k)
{
for(ll i = 0;i < k;i++)
{
for(ll j = 0;j < i;j++)cout<<j+1<<" ";
for(ll j = i;j < m-i;j++)cout<<i+1<<" ";
for(ll j = m-i;j < m;j++)cout<<m-j<<" ";
cout<<endl;
}
ll x = k + 1,y = x,st = 0;
for(ll i = k;i < n - k;i++)
{
for(ll j = 0;j < k;j++)cout<<j+1<<" ";
for(ll j = k;j < m - k;j+=2)
{
cout<<x<<" "<<x<<" ";
x++;
}
for(ll j = m-k;j < m;j++)cout<<m-j<<" ";
cout<<endl;
if(st == 0)
{
st++;
x = y;
}
else
{
st--;
y = x;
}
}
for(ll i = k-1;i >= 0;i--)
{
for(ll j = 0;j < i;j++)cout<<j+1<<" ";
for(ll j = i;j < m-i;j++)cout<<i+1<<" ";
for(ll j = m-i;j < m;j++)cout<<m-j<<" ";
cout<<endl;
}
return ;
}
void solve()
{
ll n,m,k;
cin>>n>>m>>k;
if(n % 2 == 1 || m % 2 == 1)
{
cout<<"NO"<<endl;
return ;
}
ll s = -1;
for(ll i = 0;i < min(n,m) / 2;i++)
{
ll x = (n * m - 2 * i * (n + m) + pow(2 * i,2)) / 4 + i;
if(x == k)
{
s = i;
break;
}
else if(x < k)break;
}
if(s == -1)cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
draw(n,m,s);
}
return ;
}
int main()
{
ll 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... |