Submission #761456

#TimeUsernameProblemLanguageResultExecution timeMemory
761456US3RN4M3Gardening (RMI21_gardening)C++17
100 / 100
68 ms796 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; int arr[200000]; ll w, h; int col; inline int & get(int x, int y) { return arr[x*h + y]; } pair<ll, ll> possible_range(ll n, ll m) { return {max(n, m) / 2, (n * m) / 4}; } bool fits(ll n, ll m, ll k) { pair<ll, ll> range = possible_range(n, m); return (range.first <= k && k <= range.second && k != range.second - 1); } bool create_rect(ll sx, ll sy, ll n, ll m, ll k) { if(k == (n * m) / 4) { for(int i = 0; i < n; i += 2) for(int j = 0; j < m; j += 2) { col++; get(sx + i, sy + j) = col; get(sx + i + 1, sy + j) = col; get(sx + i, sy + j + 1) = col; get(sx + i + 1, sy + j + 1) = col; } return true; } if(n != 2 && m != 2 && fits(n - 2, m - 2, k - 1)) { col++; for(int i = 0; i < n; i++) { get(sx + i, sy) = col; get(sx + i, sy + m - 1) = col; } for(int i = 0; i < m; i++) { get(sx, sy + i) = col; get(sx + n - 1, sy + i) = col; } return create_rect(sx + 1, sy + 1, n - 2, m - 2, k - 1); } if(n != 2 && fits(n - 2, m, k - (m / 2))) { for(int i = 0; i < m; i += 2) { col++; get(sx, sy + i) = col; get(sx + 1, sy + i) = col; get(sx, sy + i + 1) = col; get(sx + 1, sy + i + 1) = col; } return create_rect(sx + 2, sy, n - 2, m, k - (m / 2)); } if(m != 2 && fits(n, m - 2, k - (n / 2))) { for(int i = 0; i < n; i += 2) { col++; get(sx + i, sy) = col; get(sx + i, sy + 1) = col; get(sx + i + 1, sy) = col; get(sx + i + 1, sy + 1) = col; } return create_rect(sx, sy + 2, n, m - 2, k - (n / 2)); } cout << "NO" << endl; return false; } void solve() { ll k; cin >> w >> h >> k; if(w * h > 200000 || w & 1 || h & 1) { cout << "NO" << endl; return; } col = 0; if(create_rect(0, 0, w, h, k)) { cout << "YES" << endl; for(int i = 0; i < w; i++) for(int j = 0; j < h; j++) cout << get(i, j) << " \n"[j == h - 1]; } } main() { int t; cin >> t; while(t--) solve(); }

Compilation message (stderr)

Main.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   85 | main() {
      | ^~~~
#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...