#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,m,i,j,x,y,k,t,e,r,l;
vector<vector<ll>> a;
void f(ll x,ll y,ll z,ll w,ll k)
{
//printf("%lld %lld %lld %lld %lld \n",x,y,z,w,k);
ll i,j,n,m,q;
n=z-x+1;
m=w-y+1;
if(n==2)
{
for(j=y;j<=w;j+=2)
{
t++;
a[x][j]=t;
a[z][j]=t;
a[x][j+1]=t;
a[z][j+1]=t;
}
return;
}
q=-1;
for(i=0;i<=n-4;i+=2)
{
/*if(1+i/2*m/2+m/2-1<=k&&k<=1+i/2*m/2+(n/2-i-1)*(m/2-1)&&k!=m/2*i/2+(n/2-i-1)*(m/2-1))
{
q=i;
break;
}*/
if(m==n-i)
{
if(1+i/2*m/2+m/2-1<=k&&k<=1+i/2*m/2+(n/2-i/2-1)*(m/2-1)&&k!=m/2*i/2+(n/2-i/2-1)*(m/2-1)&&(1+i/2*m/2+m/2>k||1+i/2*m/2+m<=k))
{
q=i;
break;
}
}
else
{
if(1+i/2*m/2+m/2-1<=k&&k<=1+i/2*m/2+(n/2-i/2-1)*(m/2-1)&&k!=m/2*i/2+(n/2-i/2-1)*(m/2-1))
{
q=i;
break;
}
}
}
//printf("%lld\n",q);
for(i=y;i<=w;i+=2)
{
for(j=0;j<q;j+=2)
{
t++;
a[x+j][i]=t;
a[x+j+1][i+1]=t;
a[x+j][i+1]=t;
a[x+j+1][i]=t;
}
}
if(q!=-1)
{t++;
for(i=y;i<=w;i++)
{
a[x+q][i]=t;
a[z][i]=t;
}
for(i=x+q;i<=z;i++)
{
a[i][y]=t;
a[i][w]=t;
}}
if(q!=-1)
{
f(x+q+1,y+1,z-1,w-1,k-1-m/2*q/2);
return;
}
for(i=0;i<=m-4;i+=2)
{
if(n==m-i)
{
if(1+i/2*n/2+n/2-1<=k&&k<=1+i/2*n/2+(m/2-i/2-1)*(n/2-1)&&k!=n/2*i/2+(m/2-i/2-1)*(n/2-1)&&(1+i/2*n/2+n/2>k||1+i/2*n/2+n<=k))
{
q=i;
break;
}
}
else
{
if(1+i/2*n/2+n/2-1<=k&&k<=1+i/2*n/2+(m/2-i/2-1)*(n/2-1)&&k!=n/2*i/2+(m/2-i/2-1)*(n/2-1))
{
q=i;
break;
}
}
}
if(q!=-1)
{for(i=x;i<=z;i+=2)
for(j=0;j<q;j+=2)
{
t++;
a[i][j+y]=t;
a[i+1][j+y+1]=t;
a[i][j+y+1]=t;
a[i+1][j+y]=t;
}
t++;
for(i=x;i<=z;i++)
{
a[i][w]=t;
a[i][y+q]=t;
}
for(i=y+q;i<=w;i++)
{
a[z][i]=t;
a[x][i]=t;
}
//printf("%lld\n",q);
f(x+1,y+q+1,z-1,w-1,k-1-n/2*q/2);
return;
}
q=n-4;
for(i=y;i<=w;i+=2)
{
for(j=0;j<q;j+=2)
{
t++;
a[x+j][i]=t;
a[x+j+1][i+1]=t;
a[x+j][i+1]=t;
a[x+j+1][i]=t;
}
}
k-=q/2*m/2;
k-=m/2;
q=m-k*2;
if(q!=0)
t++;
for(i=z-3;i<=z;i++)
for(j=0;j<q;j++)
{
a[i][j+y]=t;
}
for(i=z-3;i<=z;i+=2)
for(j=y+q;j<=w;j+=2)
{
t++;
a[i][j]=t;
a[i][j+1]=t;
a[i+1][j]=t;
a[i+1][j+1]=t;
}
for(j=0;j<q-2;j+=2)
{
t++;
a[z-2][y+1+j]=t;
a[z-1][y+1+j]=t;
a[z-2][y+2+j]=t;
a[z-1][y+2+j]=t;
}
return;
}
int main()
{
scanf("%lld",&e);
for(l=0;l<e;l++)
{
r=0;
t=0;
a.clear();
scanf("%lld %lld %lld",&n,&m,&k);
a.resize(n+1);
for(i=1;i<=n;i++)
a[i].resize(m+1);
if(n%2==1||m%2==1)
{
printf("NO\n");
continue;
}
if(k==n/2*m/2)
{
for(i=1;i<=n;i+=2)
{
for(j=1;j<=m;j+=2)
{
t++;
a[i][j]=t;
a[i][j+1]=t;
a[i+1][j]=t;
a[i+1][j+1]=t;
}
}
printf("YES\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
printf("%lld ",a[i][j]);
printf("\n");
}
continue;
}
if(n==m)
{
if(k!=n/2)
{
if(k<n||k>=(n*m/4-1))
{
printf("NO\n");
continue;
}
}
f(1,1,n,m,k);
}
else
{
if(n>m)
{
n^=m^=n^=m;
r=1;
}
if(k<max(n/2,m/2)||k>=(n*m/4-1))
{
printf("NO\n");
continue;
}
f(1,1,n,m,k);
}
printf("YES\n");
for(i=1;i<=n;i++)
{for(j=1;j<=m;j++)
printf("%lld ",a[i][j]);
printf("\n");
}
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:167:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
167 | scanf("%lld",&e);
| ~~~~~^~~~~~~~~~~
Main.cpp:173:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
173 | scanf("%lld %lld %lld",&n,&m,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
844 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
844 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
12 ms |
632 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
12 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
844 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
12 ms |
632 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
12 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
10 ms |
668 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
844 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
12 ms |
632 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
12 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |