This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
fillin(n-2, m-2, st+1, k-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();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |