제출 #1143656

#제출 시각아이디문제언어결과실행 시간메모리
1143656Kaztaev_AlisherGardening (RMI21_gardening)C++20
5 / 100
13 ms5444 KiB
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second #define int ll using namespace std; using ll = long long; const ll N = 2e5+5 , inf = 2e9+7; const ll INF = 1e18 , mod = 987654321; vector<int> a[N]; int n , m , k , cur = 0; void check(){ for(int i = 1; i+1 <= n; i++){ for(int j = 1; j+1 <= m; j++){ if(a[i][j] == 0 && a[i+1][j] == 0 && a[i+1][j+1] == 0 && a[i][j+1] == 0){ a[i][j] = a[i][j+1] = a[i+1][j] = a[i+1][j+1] = ++cur; } } } return; } bool f(){ int mx = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ int cnt = a[i][j] == a[i+1][j]; cnt += a[i][j] == a[i][j+1]; cnt += a[i][j] == a[i-1][j]; cnt += a[i][j] == a[i][j-1]; if(cnt != 2) return 0; if(a[i][j] == 0) return 0; mx = max(mx , a[i][j]); } } if(mx > k) return 0; cout << "YES\n"; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cout << a[i][j] <<" "; } cout << "\n"; } return 1; } void solve(){ cin >> n >> m >> k; for(int i = 0; i <= n+1; i++){ a[i].resize(m+9); } for(int i = 0; i <= n+1; i++){ for(int j = 0; j <= m+1; j++){ a[i][j] = 0; } } if(n % 2 || m % 2){ cout << "NO\n"; return; } else { if((n/2)*(m/2) < k){ cout << "NO\n"; return; } cur = 0; ll kk = n*m-k*4+4 , kol = 0; int n1 = n , m1 = m; for(int i = 0; i < min(n/2,m/2); i++){ if(kk - (n1*2+m1*2-4) >= 0){ cur++; kol++; for(int i = kol; i <= n-kol+1; i++){ a[i][kol] = cur; a[i][m-kol+1] = cur; } for(int j = kol; j <= m-kol+1; j++){ a[kol][j] = cur; a[n-kol+1][j] = cur; } kk -= (n1*2+m1*2-4); n1-= 2; m1-= 2; kk += 4; } else if(kk - (n1*2+m1*2-4) < 0){ for(int len = 3; len <= n1; len += 2){ if((kk-len*2) % 2 == 0 && (kk-len*2)/2 <= m1){ int len2 = (kk-len*2)/2; if(len2 <= 3) continue; cur++; for(int i = kol+1; i <= kol+len+1; i++){ a[i][kol+1] = cur; a[i][kol+len2+1] = cur; } for(int i = kol+1; i <= kol+len2+1; i++){ a[kol+1][i] = cur; a[kol+len+1][i] = cur; } break; } } break; } } check(); if(!f()){ cout << "NO\n"; return; } } } /* */ signed main(){ ios; int t; cin >> t; while(t--) solve(); }
#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...