이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 < min(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{
ll posa = min(M / 2,k - min((N / 2) - 1,M / 2));
f(j,ly,ly + posa){
ans[lx][j] = ans[lx + 1][j] = ans[lx][j+1] = ans[lx+1][j+1] = k;
k--;
}
f(j,ly + posa,ry + 1){
ans[lx][j] = ans[lx][j - 1];
ans[lx + 1][j] = ans[lx + 1][j - 1];
}
N -= 2;
lx += 2;
}
}
cout<<"YES\n";
f(i,0,n){
f(j,0,m){
cout<<ans[i][j]<<" ";
}
cout<<"\n";
}
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;
}
}
assert(ok);
}
}
}
# | 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... |