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 draw1(ll n,ll m,ll v)
{
if(v != 0){
for(ll i = 1;i <= v;i++)cout<<i<<" ";
for(ll i = 0;i < m;i++)cout<<v<<" ";
for(ll i = v;i > 0;i--)cout<<i<<" ";
cout<<endl;}
ll x = v+1,y = v+1;
for(ll i = 0;i < n;i++)
{
for(ll j = 1;j <= v;j++)cout<<j<<" ";
for(ll j = 0;j < m;j+=2)
{
cout<<x<<" "<<x<<" ";
x++;
}
for(ll j = v;j > 0;j--)cout<<j<<" ";
if(i % 2 == 1)y = x;
else x = y;
cout<<endl;
}
if(v != 0){
for(ll i = 1;i <= v;i++)cout<<i<<" ";
for(ll i = 0;i < m;i++)cout<<v<<" ";
for(ll i = v;i > 0;i--)cout<<i<<" ";
cout<<endl;}
}
ll line(ll n,ll m,ll v,ll r,ll y){
for(ll i = 1;i <= v;i++)cout<<i<<" ";
for(ll i = 0;i < r;i++)cout<<v+1<<" ";
for(ll i = r;i < m;i+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll i = v;i > 0;i--)cout<<i<<" ";
cout<<endl;
return y;
}
pair<ll,ll> fline(ll n,ll m,ll v,ll r,ll x,ll y){
for(ll i = 1;i <= v;i++)cout<<i<<" ";
for(ll i = 0;i < 4;i++)cout<<v+1<<" ";
for(ll i = 5;i < r-1;i+=2)
{
cout<<x<<" "<<x<<" ";
x++;
}
cout<<v<<" ";
for(ll i = r;i < m;i+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll i = v-1;i > 0;i--)cout<<i<<" ";
cout<<endl;
swap(x,y);
for(ll i = 1;i <= v;i++)cout<<i<<" ";
cout<<v+1<<" "<<v+2<<" "<<v+2<<" "<<v+1<<" ";
for(ll i = 5;i < r-1;i+=2)
{
cout<<x<<" "<<x<<" ";
x++;
}
cout<<v<<" ";
for(ll i = r;i < m;i+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll i = v-1;i > 0;i--)cout<<i<<" ";
cout<<endl;
swap(x,y);
for(ll i = 1;i <= v;i++)cout<<i<<" ";
cout<<v+1<<" "<<v+2<<" "<<v+2<<" "<<v+1<<" ";
for(ll i = 5;i < r-1;i+=2)
{
cout<<x<<" "<<x<<" ";
x++;
}
cout<<v<<" ";
for(ll i = r;i < m;i+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll i = v-1;i > 0;i--)cout<<i<<" ";
cout<<endl;
swap(x,y);
for(ll i = 1;i <= v;i++)cout<<i<<" ";
for(ll i = 0;i < 4;i++)cout<<v+1<<" ";
for(ll i = 5;i < r-1;i+=2)
{
cout<<x<<" "<<x<<" ";
x++;
}
cout<<v<<" ";
for(ll i = r;i < m;i+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll i = v-1;i > 0;i--)cout<<i<<" ";
cout<<endl;
swap(x,y);
pair<ll,ll> s;
s.first = x;
s.second = y;
return s;
}
void draw2(ll n,ll m,ll v)
{
ll r,d,x = v + 3,y = v + 3;
if(n >= 8){
r = m;
d = n - 2;
}
else{
r = m - 2;
d = n;
}
y = line(n,m,v-1,r,y);
swap(x,y);
pair<ll,ll> s = fline(n,m,v,r,x,y);
x = s.first;y = s.second;
for(ll i = 5;i < d-1;i++){
for(ll j = 1;j <= v+1;j++)cout<<j<<" ";
for(ll j = 1;j < r-1;j+=2)
{
cout<<x<<" "<<x<<" ";
x++;
}
cout<<v+1<<" ";
for(ll j = r;j < m;j+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll j = v;j > 0;j--)cout<<j<<" ";
cout<<endl;
swap(x,y);
}
y = line(n,m,v-1,r,y);
swap(x,y);
for(ll i = d;i < n;i++){
for(ll j = 1;j < v;j++)cout<<j<<" ";
for(ll j = 0;j < m;j+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll j = v-1;j > 0;j--)cout<<j<<" ";
cout<<endl;
swap(x,y);
}
return ;
}
void draw3(ll n,ll m,ll v,ll k)
{
if(v != 0){
for(ll i = 1;i <= v;i++)cout<<i<<" ";
for(ll i = 0;i < m;i++)cout<<v<<" ";
for(ll i = v;i > 0;i--)cout<<i<<" ";
cout<<endl;
}
ll r,d,x = v+2,y = v+2;
if(k * 2 >= m){
r = m;
k -= m / 2;
d = k * 2 + 4;
}
else{
d = 4;
r = k * 2;
}
y = line(n,m,v,r,y);
swap(x,y);
for(ll i = 1;i < d-1;i++){
for(ll j = 1;j <= v+1;j++)cout<<j<<" ";
for(ll j = 1;j < r-1;j+=2)
{
cout<<x<<" "<<x<<" ";
x++;
}
cout<<v+1<<" ";
for(ll j = r;j < m;j+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll j = v;j > 0;j--)cout<<j<<" ";
cout<<endl;
swap(x,y);
}
y = line(n,m,v,r,y);
swap(x,y);
for(ll i = d;i < n;i++){
for(ll j = 1;j <= v;j++)cout<<j<<" ";
for(ll j = 0;j < m;j+=2)
{
cout<<y<<" "<<y<<" ";
y++;
}
for(ll j = v;j > 0;j--)cout<<j<<" ";
cout<<endl;
swap(x,y);
}
if(v != 0){
for(ll i = 1;i <= v;i++)cout<<i<<" ";
for(ll i = 0;i < m;i++)cout<<v<<" ";
for(ll i = v;i > 0;i--)cout<<i<<" ";
cout<<endl;
}
}
void draw(ll n,ll m,ll k,ll v)
{
for(ll i = 1;i < v;i++)
{
for(ll j = 0;j < i;j++)cout<<j+1<<" ";
for(ll j = i;j < m-i;j++)cout<<i<<" ";
for(ll j = m-i;j < m;j++)cout<<m - j<<" ";
cout<<endl;
}
ll h = v + (n - v * 2) * (m - v * 2) / 4;
if(h == k)draw1(n-v*2,m-v*2,v);
else if(h - k == 1)draw2(n-v*2+2,m-v*2+2,v);
else draw3(n-v*2,m-v*2,v,h-k);
for(ll i = v-1;i > 0;i--)
{
for(ll j = 0;j < i;j++)cout<<j+1<<" ";
for(ll j = i;j < m-i;j++)cout<<i<<" ";
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 x = (n - min(n,m) + 2) * (m - min(n,m) + 2) / 4 + min(n,m) / 2 - 1,y = n*m / 4;
if(k > y || k < x)cout<<"NO"<<endl;
else if(n == m && k == x+1)cout<<"NO"<<endl;
else if(k == y - 1)cout<<"NO"<<endl;
else
{
cout<<"YES"<<endl;
ll v = -1;
while(y >= k)
{
v++;
if(v * 2 == min(n,m))break;
y = (n - (v + 1) * 2) * (m - (v + 1) * 2) / 4 + (v + 1);
}
draw(n,m,k,v);
}
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... |