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 <bits/stdc++.h>
using namespace std;
//ifstream fin ("test.in");
//ofstream fout ("test.out");
int v[1001][1001];
int cl;
void divide(int x1, int y1, int x2, int y2, int K){
if(K == 0){
cl = -1;
return;
}
//printf("divide(%d, %d, %d, %d, %d)\n", x1, y1, x2, y2, K);
int N = x2 - x1 + 1;
int M = y2 - y1 + 1;
if(N * M == 4 * K){
///umplu cu patrate
for(int i = x1; i <= x2; i += 2){
for(int j = y1; j <= y2; j += 2){
v[i][j] = cl;
v[i + 1][j] = cl;
v[i][j + 1] = cl;
v[i + 1][j + 1] = cl;
cl++;
}
}
return;
}
else if(N == 2 || M == 2){
cl = -1;
return;
}
else {
for(int i = x1; i <= x2; i++){
v[i][y1] = cl;
v[i][y2] = cl;
}
for(int j = y1; j <= y2; j++){
v[x1][j] = cl;
v[x2][j] = cl;
}
cl++;
divide(x1 + 1, y1 + 1, x2 - 1, y2 - 1, K - 1);
}
}
void Solve()
{
int N, M, K;
cin >> N >> M >> K;
if(N % 2 == 1 || M % 2 == 1){
cout << "NO\n";
return;
}
cl = 1;
divide(1, 1, N, M, K);
if(cl == -1){
cout << "NO\n";
return;
}
cout << "YES\n";
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
cout << v[i][j] << ' ';
}
cout << "\n";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int nrTeste;
cin >> nrTeste;
for(int q = 1; q <= nrTeste; q++){
Solve();
}
return 0;
}
# | 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... |