Submission #742831

#TimeUsernameProblemLanguageResultExecution timeMemory
742831hmm789Gardening (RMI21_gardening)C++14
39 / 100
21 ms724 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' vector<vector<int>> a; int clr = 1; void solve(int l, int r, int u, int d, int k) { int n = d-u+1, m = r-l+1; if(n <= 0 || m <= 0) return; if(k == n*m/4) { for(int i = u; i <= d; i++) { for(int j = l; j <= r; j++) { if((i-u)%2==0) { if((j-l)%2==0) a[i][j] = clr; else a[i][j] = clr++; } else a[i][j] = a[i-1][j]; } } } else if(k >= n*m/4-n/2-m/2+2) { int num = n*m/4-k; if(num*2 <= m) { for(int i = l; i < l+num*2; i++) a[u][i] = a[min(d, u+3)][i] = clr; for(int i = u; i <= min(d, u+3); i++) a[i][l] = a[i][l+num*2-1] = clr; clr++; solve(l+1, l+num*2-2, u+1, min(d, u+3)-1, num-1); solve(l+num*2, r, u, min(d, u+3), r-(l+num*2)+1); solve(l, r, min(d, u+3)+1, d, k-1-(num-1)-(r-(l+num*2)+1)); } else { int cols = (num-m/2)*2+4; for(int i = l; i <= r; i++) a[u][i] = a[u+cols-1][i] = clr; for(int i = u; i < u+cols; i++) a[i][l] = a[i][r] = clr; clr++; solve(l+1, r-1, u+1, u+cols-2, (r-l-1)*(cols-2)/4); solve(l, r, u+cols, d, k-1-(r-l-1)*(cols-2)/4); } } else if(k == n*m/4-n/2-m/2+1) { for(int i = l; i <= r-2; i++) a[u][i] = a[d][i] = clr; for(int i = u; i <= d; i++) a[i][l] = a[i][r-2] = clr; clr++; for(int i = l+1; i <= l+4; i++) a[u+1][i] = a[u+4][i] = clr; for(int i = u+1; i <= u+4; i++) a[i][l+1] = a[i][l+4] = clr; clr++; solve(l+2, l+3, u+2, u+3, 1); solve(l+1, l+4, u+5, d-1, (d-1-u-5+1)); solve(l+5, r-3, u+1, d-1, (r-3-l-5+1)*(d-1-u-1+1)/4); solve(r-1, r, u, d, k-3-(d-1-u-5+1)-(r-3-l-5+1)*(d-1-u-1+1)/4); } else { for(int i = l; i <= r; i++) a[u][i] = a[d][i] = clr; for(int i = u; i <= d; i++) a[i][l] = a[i][r] = clr; clr++; solve(l+1, r-1, u+1, d-1, k-1); } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) { int n, m, k; cin >> n >> m >> k; if(n % 2 == 1 || m % 2 == 1 || k > n*m/4 || k < max(n, m)/2 || k == n*m/4-1 || (n==m&&k==n/2+1)) { cout << "NO" << endl; continue; } a.clear(); for(int i = 0; i < n; i++) { vector<int> v; for(int j = 0; j < m; j++) v.push_back(0); a.push_back(v); } clr = 1; solve(0, m-1, 0, n-1, k); cout << "YES" << endl; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) cout << a[i][j] << " "; cout << endl; } } }
#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...