제출 #742373

#제출 시각아이디문제언어결과실행 시간메모리
742373maomao90Gardening (RMI21_gardening)C++17
18 / 100
23 ms10068 KiB
// Hallelujah, praise the one who set me free // Hallelujah, death has lost its grip on me // You have broken every chain, There's salvation in your name // Jesus Christ, my living hope #include <bits/stdc++.h> using namespace std; #define REP(i, s, e) for (int i = (s); i < (e); i++) #define RREP(i, s, e) for (int i = (s); i >= (e); i--) template <class T> inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;} template <class T> inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;} typedef long long ll; typedef long double ld; #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define SZ(_a) (int) _a.size() #define pb push_back typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<iii> viii; #ifndef DEBUG #define cerr if (0) cerr #endif const int INF = 1000000005; const ll LINF = 1000000000000000005ll; const int MAXN = 200005; int t; int n, m; ll k; vi g[MAXN]; int main() { #ifndef DEBUG ios::sync_with_stdio(0), cin.tie(0); #endif cin >> t; while (t--) { cin >> n >> m >> k; if ((n & 1) || (m & 1)) { cout << "NO\n"; continue; } ll mn = n / 2, mx = (ll) (n / 2) * (n / 2); if (k < mn || k > mx) { cout << "NO\n"; continue; } if (k == mn + 1 || k == mx - 1) { cout << "NO\n"; continue; } cout << "YES\n"; REP (i, 1, n + 1) { g[i] = vi(m + 1); } int rt = -1; RREP (i, n / 2, 1) { if ((ll) i * i + n / 2 - i <= k) { rt = i; break; } } assert(rt != -1); int ptr = 1; if ((ll) (rt + 1) * (rt + 1) + n / 2 - rt - 2 == k) { RREP (k, n / 2, rt + 2) { for (int i : {ptr, n - ptr + 1}) { REP (j, ptr, m - ptr + 2) { g[i][j] = ptr; } } REP (i, ptr, n - ptr + 2) { for (int j : {ptr, m - ptr + 1}) { g[i][j] = ptr; } } ptr++; } REP (i, ptr, n - ptr + 2) { g[i][ptr + 1] = ptr - 1; } int optr = ptr; for (int i = optr - 1; i <= n - optr + 1; i += 2) { REP (a, 0, 2) { REP (b, 0, 2) { g[i + a][optr - 1 + b] = ptr; } } ptr++; } for (int i = optr; i <= n - optr + 1; i += 2) { for (int j = optr + 2; j <= m - optr + 1; j += 2) { if (i - 4 < optr && j + 4 > m - optr + 1) { continue; } REP (a, 0, 2) { REP (b, 0, 2) { g[i + a][j + b] = ptr; } } ptr++; } } REP (i, optr, optr + 4) { RREP (j, m - optr + 1, m - optr - 2) { g[i][j] = ptr; } } ptr++; REP (i, optr + 1, optr + 3) { RREP (j, m - optr, m - optr - 1) { g[i][j] = ptr; } } ptr++; } else { ll need = k - ((ll) rt * rt + n / 2 - rt); RREP (k, n / 2, rt + 1) { for (int i : {ptr, n - ptr + 1}) { REP (j, ptr, m - ptr + 2) { g[i][j] = ptr; } } REP (i, ptr, n - ptr + 2) { for (int j : {ptr, m - ptr + 1}) { g[i][j] = ptr; } } ptr++; } int optr = ptr; int lft = m - optr - 1; if (need < rt) { lft = optr + need * 2 - 1; } for (int i = optr - 1; i <= n - optr + 2; i += 2) { for (int j = optr - 1; j < lft; j += 2) { REP (a, 0, 2) { REP (b, 0, 2) { g[i + a][j + b] = ptr; } } ptr++; } } REP (i, optr, n - optr + 2) { g[i][lft] = optr - 1; } need = max(0ll, need - rt + 1); cerr << optr << '\n'; for (int i = n - optr + 1; i > n - optr + 1 - 2 * need; i -= 2) { for (int j = lft; j <= n - optr + 1; j += 2) { REP (a, 0, 2) { REP (b, 0, 2) { g[i + a][j + b] = ptr; } } ptr++; } REP (j, lft, n - optr + 3) { g[i - 1][j] = optr - 1; } } for (int i = optr; i <= n - optr + 1 - 2 * need; i += 2) { for (int j = lft + 1; j <= n - optr; j += 2) { REP (a, 0, 2) { REP (b, 0, 2) { g[i + a][j + b] = ptr; } } ptr++; } } } REP (i, 1, n + 1) { REP (j, 1, n + 1) { cout << setfill(' ') << setw(2) << g[i][j] << ' '; } cout << '\n'; } assert(ptr - 1 == k); } }
#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...