#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
bool check(int N, int M, int K)
{
if (N % 2 || M % 2) return false;
if (K < max(N/2, M/2)) return false;
if (K > N * M / 4) return false;
if (K == N * M / 4 - 1) return false;
if (N == M && K == N / 2 + 1) return false;
return true;
}
vector<vector<int>> v;
void color(int n, int m, int st, int x, int y)
{
if (n == 2) {
//st부터 k개의 색을 채우기
for (int i = y; i <= y + m - 1; i++) {
int clr = (i - y) / 2 + st;
v[x][i] = v[x+1][i] = clr;
}
return;
}
else if (m == 2) {
for (int i = x; i <= x + n - 1; i++) {
int clr = (i - x) / 2 + st;
v[i][y] = v[i][y+1] = clr;
}
return;
}
}
void fillin(int n, int m, int st, int k, int x, int y) //(x, y)부터 (n, m)칸 채우기
{
if (n == 2 || m == 2) color(n, m, st, x, y);
else {
if (check(n, m-2, k-n/2)) {
fillin(n, m-2, st, k-n/2, x, y);
color(n, 2, st+k-n/2, x, y+m-2);
}
else if (check(n-2, m, k-m/2)) {
fillin(n-2, m, st, k-m/2, x, y);
color(2, m, st+k-m/2, x+n-2, y);
}
else if (check(n-2, m-2, k-1)) {
for (int j = y; j < y + m; j++) v[x][j] = v[x+n-1][j] = st;
for (int i = x; i < x + n; i++) v[i][y] = v[i][y+m-1] = st;
color(n-2, m-2, st+1, x+1, y+1);
}
}
}
void solve()
{
int N, M, K; cin >> N >> M >> K;
v.resize(N);
for (int i = 0; i < N; i++) v[i].resize(M);
if (!check(N, M, K)) {
cout << "NO\n";
return;
}
fillin(N, M, 1, K, 0, 0);
cout << "YES\n";
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cout << v[i][j] << ' ';
}
cout << '\n';
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T; cin >> T;
while (T--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
912 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
912 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
9 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
912 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
9 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Failed |
11 ms |
596 KB |
Output contains values not between 1 and k |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Failed |
10 ms |
576 KB |
Output contains values not between 1 and k |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Failed |
4 ms |
468 KB |
Output contains values not between 1 and k |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
912 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
9 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
10 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Failed |
11 ms |
596 KB |
Output contains values not between 1 and k |
5 |
Halted |
0 ms |
0 KB |
- |