#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;
const int CUTLINE=4500;
int a1[200000][60];
int a2[60][200000];
int a3[5000][5000];
void sqr(int s,int e,int l,int r,int c,int t)
{
if(t==1)
for(int i=s;i<e;i++)
for(int j=l;j<r;j++)
a1[i][j]=c;
else if(t==2)
for(int i=s;i<e;i++)
for(int j=l;j<r;j++)
a2[i][j]=c;
else
for(int i=s;i<e;i++)
for(int j=l;j<r;j++)
a3[i][j]=c;
}
void fillmp(int s,int e,int l,int r,int c,int t)
{
int n=(e-s)/2,m=(r-l)/2;
if(c==n*m)
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
sqr(s+i*2,s+i*2+2,l+j*2,l+j*2+2,c--,t);
}
else if(c-1<=(n-1)*(m-1)-2 || c-1==(n-1)*(m-1))
{
sqr(s,e,l,l+1,c,t);
sqr(s,e,r-1,r,c,t);
sqr(s,s+1,l,r,c,t);
sqr(e-1,e,l,r,c,t);
fillmp(s+1,e-1,l+1,r-1,c-1,t);
}
else if(n>m)
{
for(int j=0;j<m;j++)
sqr(s,s+2,l+j*2,l+j*2+2,c--,t);
fillmp(s+2,e,l,r,c,t);
}
else
{
for(int i=0;i<n;i++)
sqr(s+i*2,s+i*2+2,l,l+2,c--,t);
fillmp(s,e,l+2,r,c,t);
}
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T;
cin >> T;
while(T--)
{
int n,m,k;
cin >> n >> m >> k;
if(n%2 || m%2)
{
cout << "NO\n";
continue;
}
if(k>n*m/4 || k==n*m/4-1 || k<max(n,m)/2)
{
cout << "NO\n";
continue;
}
if(n>CUTLINE)
{
fillmp(0,n,0,m,k,1);
cout << "YES\n";
for(int i=0;i<n;i++,cout << '\n')
for(int j=0;j<m;j++)
cout << a1[i][j] << ' ';
}
else if(m>CUTLINE)
{
fillmp(0,n,0,m,k,2);
cout << "YES\n";
for(int i=0;i<n;i++,cout << '\n')
for(int j=0;j<m;j++)
cout << a2[i][j] << ' ';
}
else
{
fillmp(0,n,0,m,k,3);
cout << "YES\n";
for(int i=0;i<n;i++,cout << '\n')
for(int j=0;j<m;j++)
cout << a3[i][j] << ' ';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
860 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
860 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
6 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
6 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
860 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
6 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
6 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Execution timed out |
1081 ms |
348 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1041 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1073 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
860 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
6 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
6 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Execution timed out |
1081 ms |
348 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |