Submission #923963

#TimeUsernameProblemLanguageResultExecution timeMemory
923963GrindMachineGardening (RMI21_gardening)C++17
100 / 100
18 ms1116 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "YES" << endl #define no cout << "NO" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(x) 42 #endif /* */ const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; ll f(ll n, ll m){ return max(n/2,m/2); } ll g(ll n, ll m){ return (n/2)*(m/2); } vector<vector<ll>> a; ll ptr; bool ok; void go(ll li, ll ri, ll lj, ll rj, ll k){ ll n = ri-li+1; ll m = rj-lj+1; if(n == 0 and m == 0){ if(k) ok = false; return; } // place on border if(f(n-2,m-2) <= k-1 and k-1 <= g(n-2,m-2) and k-1 != g(n-2,m-2)-1){ ptr++; for(int j = lj; j <= rj; ++j){ a[li][j] = a[ri][j] = ptr; } for(int i = li; i <= ri; ++i){ a[i][lj] = a[i][rj] = ptr; } go(li+1,ri-1,lj+1,rj-1,k-1); return; } // split by row for(int i = 2; i < n; i += 2){ ll mnl = f(i,m), mxl = g(i,m); ll mnr = f(n-i,m), mxr = g(n-i,m); if(mnl+mnr <= k and k <= mxl+mxr){ for(int k1 = mnl; k1 <= mxl; ++k1){ ll k2 = k-k1; if(k2 >= mnr and k2 <= mxr and k1 != mxl-1 and k2 != mxr-1){ go(li,li+i-1,lj,rj,k1); go(li+i,ri,lj,rj,k2); return; } } } } // split by col for(int j = 2; j < m; j += 2){ ll mnl = f(n,j), mxl = g(n,j); ll mnr = f(n,m-j), mxr = g(n,m-j); if(mnl+mnr <= k and k <= mxl+mxr){ for(int k1 = mnl; k1 <= mxl; ++k1){ ll k2 = k-k1; if(k2 >= mnr and k2 <= mxr and k1 != mxl-1 and k2 != mxr-1){ go(li,ri,lj,lj+j-1,k1); go(li,ri,lj+j,rj,k2); return; } } } } ok = false; } void solve(int test_case) { ll n,m,k; cin >> n >> m >> k; if((n&1) or (m&1)){ no; return; } if(!(f(n,m) <= k and k <= g(n,m))){ no; return; } if(k == g(n,m)-1){ no; return; } a = vector<vector<ll>>(n+5,vector<ll>(m+5)); ptr = 0; ok = true; go(1,n,1,m,k); if(!ok){ no; return; } yes; rep1(i,n){ rep1(j,m){ cout << a[i][j] << " "; } cout << endl; } } int main() { fastio; int t = 1; cin >> t; rep1(i, t) { solve(i); } return 0; }
#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...