제출 #570719

#제출 시각아이디문제언어결과실행 시간메모리
570719Theo830Gardening (RMI21_gardening)C++17
5 / 100
27 ms852 KiB
#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; } else{ ll num = (n * m) / 4; num -= k; ll X = sqrt(num) + 1; if(X * (X - 1) != num){ 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(N >= M){ 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{ assert(0); cout<<"NO\n"; } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...