#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;
ll X;
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;
}
else{
ll num = (n * m) / 4;
num -= k;
X = sqrt(num) + 1;
if(X * (X - 1) != num || (2 * X) > min(n,m) || X > k){
ok = 0;
}
}
if(!ok){
cout<<"NO\n";
}
else{
ll ans[n+5][m+5];
ll lx = 0,rx = 2*X - 1,ly = 0,ry= 2*X - 1;
while(lx < rx){
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--;
k--;
}
f(i,0,n){
f(j,0,m){
if(i >= 2*X || j >= 2*X){
ans[i][j] = ans[i+1][j] = ans[i][j+1] = ans[i+1][j+1] = k;
k--;
}
j++;
}
i++;
}
if(ok){
cout<<"YES\n";
f(i,0,n){
f(j,0,m){
cout<<ans[i][j]<<" ";
}
cout<<"\n";
}
}
else{
assert(0);
cout<<"NO\n";
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
716 KB |
Correct! Azusa and Laika like the garden :) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
716 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Failed |
5 ms |
468 KB |
Incorrect output |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
716 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Failed |
5 ms |
468 KB |
Incorrect output |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
2 ms |
328 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
1 ms |
340 KB |
Incorrect output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
716 KB |
Correct! Azusa and Laika like the garden :) |
2 |
Failed |
5 ms |
468 KB |
Incorrect output |
3 |
Halted |
0 ms |
0 KB |
- |