#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i = a; i < b; i++)
bool fe;
int c;
pair<int,int> range(int n, int m){
if(n == 2) return {m/2, m/2};
return {n*m/4 - m/2, n*m/4};
}
void print(vector <vector<int>> v){
int n = v.size(), m = v[0].size();
if(!fe){
f(i,0,n) { f(j,0,m) cout << ((v[i][j] == 0) ? c : v[i][j]) << " "; cout << "\n"; }
}
else{
f(i,0,m) { f(j,0,n) cout << ((v[j][i] == 0) ? c : v[j][i]) << " "; cout << "\n"; }
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t; cin >> t;
while(t--){
int n, m, k;
cin >> n >> m >> k;
if(n&1 or m&1){
cout << "NO\n";
continue;
}
fe = 0;
if(n > m) {
fe = 1;
swap(n, m);
}
vector <vector<int>> v(n, vector <int> (m));
bool ra = 0;
int ni = n, mi = m;
int xi = 0, yi = 0;
c = 1;
while(1){
pair<int,int> p = range(ni, mi);
if(p.second < k or k < p.first){
f(i,xi,xi+ni){
v[i][yi] = v[i][yi + mi - 1] = c;
}
f(i,yi,yi+mi){
v[xi][i] = v[xi + ni - 1][i] = c;
}
c++, k--;
xi++, yi++;
ni -= 2, mi -= 2;
if(ni == 0){
ra = 1;
cout << "NO\n";
break;
}
}
else break;
}
if(ra) continue;
if(ni == 2){
for(int i = yi; i < yi+mi-1; i += 2){
v[xi][i] = v[xi][i+1] = c;
v[xi+1][i] = v[xi+1][i+1] = c;
c++;
}
}
else{
for(int i = xi; i < xi+ni-4; i += 2){
for(int j = yi; j < yi+mi-1; j += 2){
v[i][j] = v[i][j+1] = c;
v[i+1][j] = v[i+1][j+1] = c;
c++;
k--;
}
}
int L = 2*k - mi;
if(mi - L < 4 and mi - L > 0){
cout << "NO\n";
ra = 1;
}
int e = xi + ni - 1;
for(int i = yi; i < yi+L-1; i += 2){
v[e-3][i] = v[e-3][i+1] = c;
v[e-2][i] = v[e-2][i+1] = c;
c++;
v[e-1][i] = v[e-1][i+1] = c;
v[e][i] = v[e][i+1] = c;
c++;
}
for(int i = yi+L+1; i < yi+mi-1; i += 2){
v[e-2][i] = v[e-2][i+1] = c;
v[e-1][i] = v[e-1][i+1] = c;
c++;
}
}
if(!ra){
cout << "YES\n";
print(v);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
844 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
844 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
668 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
13 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
844 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
668 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
13 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Failed |
8 ms |
596 KB |
Incorrect output |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
5 ms |
468 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
2 ms |
340 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
844 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Correct |
8 ms |
668 KB |
Correct! Azusa and Laika like the garden :) |
3 |
Correct |
13 ms |
596 KB |
Correct! Azusa and Laika like the garden :) |
4 |
Failed |
8 ms |
596 KB |
Incorrect output |
5 |
Halted |
0 ms |
0 KB |
- |