#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
int cul = 0;
bool ok(int n,int m, int c)
{
if(n%2==1 || m%2==1)
{
return false;
}
if(c == (n / 2) * (m / 2) - 1)
{
return false;
}
if(c < max(n / 2, m / 2))
{
return false;
}
if(c > (n / 2) * (m / 2))
{
return false;
}
if(n==m && c==max(n / 2, m / 2) + 1)
{
return false;
}
return true;
}
void border(int x, int y, int n, int m)
{
if(n<=0 || m<=0)
{
return;
}
++cul;
for(int i=x;i<=x+n-1;i++)
{
a[i][y] = a[i][y + m - 1] = cul;
}
for(int j=y;j<=y+m-1;j++)
{
a[x][j] = a[x + n - 1][j] = cul;
}
}
void Fill(int x, int y, int n, int m)
{
if(n<=0 || m<=0)
{
return;
}
for(int i=x;i<=x+n-1;i+=2)
{
for(int j=y;j<=y+m-1;j+=2)
{
++cul;
a[i][j] = a[i+1][j] = a[i][j+1] = a[i+1][j+1] = cul;
}
}
}
void afis(int n, int m)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<a[i][j]<<' ';
}
cout<<'\n';
}
}
void clear_mat(int n, int m)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
a[i][j] = 0;
}
}
}
void solve_test()
{
int n,m,c;
cin>>n>>m>>c;
if(!ok(n,m,c))
{
cout<<"NO"<<'\n';
return;
}
cout<<"YES"<<'\n';
clear_mat(n,m);
cul = 0;
int auxn = n;
int auxm = m;
int nr = (n / 2) * (m / 2);
vector<int> s;
s.push_back(nr);
while(n && m)
{
nr -= (n / 2) + (m / 2) - 2;
n -= 2;
m -= 2;
s.push_back(nr);
}
int poz = 0;
for(int i=0;i<s.size();i++)
{
if(c <= s[i])
{
poz = i;
}
}
n = auxn;
m = auxm;
int x = 1, y = 1;
for(int i=1;i<=poz;i++)
{
border(x,y,n,m);
++x;
++y;
n -= 2;
m -= 2;
}
if(c == s[poz])
{
Fill(x,y,n,m);
afis(auxn,auxm);
return;
}
if(c == s[poz] - 1)
{
--cul;
n += 2;
m += 2;
--x;
--y;
if(n < m)
{
Fill(x,y,n,2);
border(x,y+2,n,m-2);
Fill(x+1,y+3,n-2,m-8);
Fill(x+1,y+m-5,n-6,4);
border(x+n-5,y+m-5,4,4);
Fill(x+n-4,y+m-4,2,2);
}
else
{
Fill(x,y,2,m);
border(x+2,y,n-2,m);
Fill(x+3,y+1,n-8,m-2);
Fill(x+n-5,y+1,4,m-6);
border(x+n-5,y+m-5,4,4);
Fill(x+n-4,y+m-4,2,2);
}
afis(auxn,auxm);
return;
}
int nr_dif = s[poz] - c;
int l_dif = 4 + 2 * (nr_dif - 2);
int c_dif = 4;
if(l_dif > n)
{
c_dif += (l_dif - n);
l_dif = n;
}
Fill(x,y,n,m - c_dif);
Fill(x,y + m - c_dif,n - l_dif,c_dif);
border(x + n - l_dif, y + m - c_dif, l_dif, c_dif);
Fill(x + n - l_dif + 1, y + m - c_dif + 1, l_dif - 2, c_dif - 2);
afis(auxn,auxm);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
for(int test=1;test<=t;test++)
{
solve_test();
}
return 0;
}
Compilation message
Main.cpp: In function 'void solve_test()':
Main.cpp:115:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for(int i=0;i<s.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
872 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
872 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
9 ms |
648 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
872 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
9 ms |
648 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
10 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
13 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
748 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
8 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
8 ms |
852 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
9 ms |
712 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
8 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
9 ms |
852 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
8 ms |
768 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
11 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
8 ms |
712 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
9 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
8 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
11 ms |
720 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
3 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
5 ms |
592 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
5 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
3 ms |
588 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
4 ms |
592 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
4 ms |
588 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
6 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
2 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
14 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
15 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
16 |
Correct |
3 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
17 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
872 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
9 ms |
648 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
600 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
10 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
13 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
9 ms |
748 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
8 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
8 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
8 ms |
852 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
9 ms |
712 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
8 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
9 ms |
852 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
8 ms |
768 KB |
Correct! Azusa and Laika like the garden :) |
14 |
Correct |
11 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
15 |
Correct |
8 ms |
712 KB |
Correct! Azusa and Laika like the garden :) |
16 |
Correct |
9 ms |
848 KB |
Correct! Azusa and Laika like the garden :) |
17 |
Correct |
8 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
18 |
Correct |
11 ms |
720 KB |
Correct! Azusa and Laika like the garden :) |
19 |
Correct |
5 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
20 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
21 |
Correct |
3 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
22 |
Correct |
5 ms |
592 KB |
Correct! Azusa and Laika like the garden :) |
23 |
Correct |
5 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
24 |
Correct |
3 ms |
588 KB |
Correct! Azusa and Laika like the garden :) |
25 |
Correct |
4 ms |
592 KB |
Correct! Azusa and Laika like the garden :) |
26 |
Correct |
4 ms |
588 KB |
Correct! Azusa and Laika like the garden :) |
27 |
Correct |
6 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
28 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
29 |
Correct |
2 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
30 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
31 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
32 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
33 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
34 |
Correct |
3 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
35 |
Correct |
4 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
36 |
Correct |
12 ms |
980 KB |
Correct! Azusa and Laika like the garden :) |
37 |
Correct |
13 ms |
2356 KB |
Correct! Azusa and Laika like the garden :) |
38 |
Correct |
15 ms |
1364 KB |
Correct! Azusa and Laika like the garden :) |
39 |
Correct |
12 ms |
1720 KB |
Correct! Azusa and Laika like the garden :) |
40 |
Correct |
12 ms |
980 KB |
Correct! Azusa and Laika like the garden :) |
41 |
Correct |
12 ms |
1204 KB |
Correct! Azusa and Laika like the garden :) |
42 |
Correct |
12 ms |
992 KB |
Correct! Azusa and Laika like the garden :) |
43 |
Correct |
13 ms |
980 KB |
Correct! Azusa and Laika like the garden :) |
44 |
Correct |
13 ms |
980 KB |
Correct! Azusa and Laika like the garden :) |
45 |
Correct |
17 ms |
2388 KB |
Correct! Azusa and Laika like the garden :) |
46 |
Correct |
13 ms |
2120 KB |
Correct! Azusa and Laika like the garden :) |
47 |
Correct |
13 ms |
948 KB |
Correct! Azusa and Laika like the garden :) |
48 |
Correct |
13 ms |
972 KB |
Correct! Azusa and Laika like the garden :) |
49 |
Correct |
13 ms |
1236 KB |
Correct! Azusa and Laika like the garden :) |
50 |
Correct |
13 ms |
976 KB |
Correct! Azusa and Laika like the garden :) |
51 |
Correct |
11 ms |
1856 KB |
Correct! Azusa and Laika like the garden :) |
52 |
Correct |
13 ms |
936 KB |
Correct! Azusa and Laika like the garden :) |
53 |
Correct |
12 ms |
968 KB |
Correct! Azusa and Laika like the garden :) |
54 |
Correct |
13 ms |
972 KB |
Correct! Azusa and Laika like the garden :) |
55 |
Correct |
14 ms |
912 KB |
Correct! Azusa and Laika like the garden :) |
56 |
Correct |
17 ms |
2496 KB |
Correct! Azusa and Laika like the garden :) |
57 |
Correct |
14 ms |
916 KB |
Correct! Azusa and Laika like the garden :) |
58 |
Correct |
12 ms |
1412 KB |
Correct! Azusa and Laika like the garden :) |
59 |
Correct |
13 ms |
2388 KB |
Correct! Azusa and Laika like the garden :) |
60 |
Correct |
14 ms |
1268 KB |
Correct! Azusa and Laika like the garden :) |