#include <bits/stdc++.h>
using namespace std;
const int c=200005;
vector<int> ans[c];
bool jo(int n, int m, int k) {
int a=max(n, m)/2, b=n*m/4;
if (n%2 || m%2 || k<a || k>b || k==b-1 || (n==m && k==a+1)) return false;
return true;
}
void rec(int n1, int n2, int m1, int m2, int k) {
int n=n2-n1+1, m=m2-m1+1;
if (n==0 || m==0) {
return;
}
if (jo(n-2, m-2, k-1)) {
for (int i=n1; i<=n2; i++) {
ans[i][m1]=k, ans[i][m2]=k;
}
for (int i=m1; i<=m2; i++) {
ans[n1][i]=k, ans[n2][i]=k;
}
return rec(n1+1, n2-1, m1+1, m2-1, k-1);
}
if (jo(n-2, m, k-(m/2))) {
for (int i=m1; i<=m2; i+=2) {
ans[n1][i]=ans[n1][i+1]=ans[n1+1][i]=ans[n1+1][i+1]=k;
k--;
}
return rec(n1+2, n2, m1, m2, k);
}
if (jo(n, m-2, k-(n/2))) {
for (int i=n1; i<=n2; i+=2) {
ans[i][m1]=ans[i+1][m1]=ans[i][m1+1]=ans[i+1][m1+1]=k;
k--;
}
return rec(n1, n2, m1+2, m2, k);
}
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
if (!jo(n, m, k)) {
cout << "NO\n";
return;
}
for (int i=1; i<=m; i++) {
ans[i].resize(m+1);
}
rec(1, n, 1, m, k);
cout << "YES\n";
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cout << ans[i][j] << " ";
}
cout << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
int w;
cin >> w;
while (w--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
5716 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
5716 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
12 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
11 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
5716 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
12 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
11 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
10 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
15 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
9 ms |
5424 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
8 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
8 ms |
5380 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
10072 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
5716 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
12 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
11 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Correct |
10 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
5 |
Correct |
15 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
6 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
7 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
8 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
9 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
10 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
11 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
12 |
Correct |
9 ms |
5424 KB |
Correct! Azusa and Laika like the garden :) |
13 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
14 |
Correct |
8 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
15 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
16 |
Correct |
8 ms |
5464 KB |
Correct! Azusa and Laika like the garden :) |
17 |
Correct |
8 ms |
5380 KB |
Correct! Azusa and Laika like the garden :) |
18 |
Correct |
7 ms |
5468 KB |
Correct! Azusa and Laika like the garden :) |
19 |
Runtime error |
6 ms |
10072 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |