#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define ull unsigned ll
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
const ll dx[4] = {0,0,1,-1};
const ll dy[4] = {1,-1,0,0};
bool in(ll x,ll y,ll n,ll m){
if(min(x,y) >= 0 && x < n && y < m){
return true;
}
return false;
}
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t;
cin>>t;
while(t--){
ll n,m,k;
cin>>n>>m>>k;
bool ok = 1;
if(n % 2 == 1 || m % 2 == 1){
ok = 0;
}
else if(k > (n / 2) * (m / 2)){
ok = 0;
}
else if(k < max(n / 2,m / 2)){
ok = 0;
}
if(!ok){
cout<<"NO\n";
}
else{
ll ans[n+5][m+5];
ll N = n,M = m;
ll lx = 0,rx = N - 1,ly = 0,ry = M - 1;
while(k){
if(k == min(N / 2,M / 2)){
f(j,ly,ry + 1){
ans[lx][j] = k;
ans[rx][j] = k;
}
f(i,lx,rx + 1){
ans[i][ly] = k;
ans[i][ry] = k;
}
lx++;
rx--;
ly++;
ry--;
N -= 2;
M -= 2;
k--;
}
else{
if(M / 2 <= k - min((N / 2) - 1,M / 2)){
f(j,ly,ry + 1){
ans[lx][j] = ans[lx + 1][j] = ans[lx][j+1] = ans[lx+1][j+1] = k;
k--;
j++;
}
N -= 2;
lx += 2;
}
else{
f(i,lx,rx + 1){
ans[i][ly] = ans[i+1][ly] = ans[i][ly+1] = ans[i+1][ly+1] = k;
k--;
i++;
}
M -= 2;
ly += 2;
}
}
}
f(i,0,n){
f(j,0,m){
ll posa = 0;
f(k,0,4){
ll x = i + dx[k],y = j + dy[k];
if(in(x,y,n,m)){
posa += ans[i][j] == ans[x][y];
}
}
ok &= posa == 2;
}
}
if(ok){
cout<<"YES\n";
f(i,0,n){
f(j,0,m){
cout<<ans[i][j]<<" ";
}
cout<<"\n";
}
}
else{
cout<<"NO\n";
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Runtime error |
82 ms |
121676 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Runtime error |
82 ms |
121676 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
428 ms |
524288 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
440 ms |
524288 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
724 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Runtime error |
82 ms |
121676 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |