Submission #742542

# Submission time Handle Problem Language Result Execution time Memory
742542 2023-05-16T12:42:21 Z maomao90 Gardening (RMI21_gardening) C++17
23 / 100
20 ms 5460 KB
// 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];


namespace st4 {
    int main() {
        ll mn = n / 2, mx = (ll) (n / 2) * (n / 2);
        if (k < mn || k > mx) {
            cout << "NO\n";
            return 0;
        }
        if (k == mn + 1 || k == mx - 1) {
            cout << "NO\n";
            return 0;
        }
        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);
        return 0;
    }
}

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;
        }
        if (n == 2 && m <= 4) {
            if (k != m / 2) {
                cout << "NO\n";
            } else {
                cout << "YES\n";
                REP (i, 0, n) {
                    REP (j, 0, m) {
                        cout << j / 2 + 1 << ' ';
                    }
                    cout << '\n';
                }
            }
            continue;
        }
        if (m == 2 && n <= 4) {
            if (k != n / 2) {
                cout << "NO\n";
            } else {
                cout << "YES\n";
                REP (i, 0, n) {
                    REP (j, 0, m) {
                        cout << i / 2 + 1 << ' ';
                    }
                    cout << '\n';
                }
            }
            continue;
        }
        if (n == m) {
            st4::main();
            continue;
        }
        ll mx = (ll) n / 2 * m / 2, mn = max(n, m) / 2;
        if (k < mn || k > mx) {
            cout << "NO\n";
            return 0;
        }
        if (k == mx - 1) {
            cout << "NO\n";
            return 0;
        }
        cout << "YES\n";
        bool swp = 0;
        if (n > m) {
            swap(n, m);
            swp = 1;
        }
        REP (i, 1, n + 1) {
            g[i] = vi(m + 1);
        }
        int rt = -1;
        RREP (i, n / 2, 1) {
            if ((ll) i * (m / 2 - n / 2 + i) + n / 2 - i <= k) {
                rt = i;
                break;
            }
        }
        assert(rt != -1);
        int ptr = 1;
        if ((ll) (rt + 1) * (m / 2 - n / 2 + 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 * (m / 2 - n / 2 + rt) + n / 2 - rt);
            cerr << ' ' << need << ' ' << rt << '\n';
            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 = min((ll) m - optr - 1, optr + need * 2 - 1);
            REP (i, 1, n + 1) {
                REP (j, 1, m + 1) {
                    cerr << g[i][j] << ' ';
                }
                cerr << '\n';
            }
            cerr << lft << '\n';
            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 -= min(need, (ll) (lft - optr + 1) / 2);
            cerr << optr << ' ' << need << '\n';
            for (int i = n - optr + 1; i > n - optr + 1 - 2 * need; i -= 2) {
                for (int j = lft; j <= m - optr + 1; j += 2) {
                    REP (a, 0, 2) {
                        REP (b, 0, 2) {
                            g[i + a][j + b] = ptr;
                        }
                    }
                    ptr++;
                }
                REP (j, lft, m - 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 <= m - optr; j += 2) {
                    REP (a, 0, 2) {
                        REP (b, 0, 2) {
                            g[i + a][j + b] = ptr;
                        }
                    }
                    ptr++;
                }
            }
        }
        if (swp) {
            REP (i, 1, m + 1) {
                REP (j, 1, n + 1) {
                    cout << setfill(' ') << setw(2) << g[j][i] << ' ';
                }
                cout << '\n';
            }
        } else {
            REP (i, 1, n + 1) {
                REP (j, 1, m + 1) {
                    cout << setfill(' ') << setw(2) << g[i][j] << ' ';
                }
                cout << '\n';
            }
        }
        assert(ptr - 1 == k);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5460 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5460 KB Correct! Azusa and Laika like the garden :)
2 Incorrect 3 ms 4948 KB Unexpected end of file - token expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5460 KB Correct! Azusa and Laika like the garden :)
2 Incorrect 3 ms 4948 KB Unexpected end of file - token expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5352 KB Correct! Azusa and Laika like the garden :)
2 Correct 14 ms 5404 KB Correct! Azusa and Laika like the garden :)
3 Correct 14 ms 5432 KB Correct! Azusa and Laika like the garden :)
4 Correct 17 ms 5388 KB Correct! Azusa and Laika like the garden :)
5 Correct 12 ms 5348 KB Correct! Azusa and Laika like the garden :)
6 Correct 12 ms 5332 KB Correct! Azusa and Laika like the garden :)
7 Correct 13 ms 5392 KB Correct! Azusa and Laika like the garden :)
8 Correct 12 ms 5332 KB Correct! Azusa and Laika like the garden :)
9 Correct 12 ms 5332 KB Correct! Azusa and Laika like the garden :)
10 Correct 12 ms 5332 KB Correct! Azusa and Laika like the garden :)
11 Correct 12 ms 5356 KB Correct! Azusa and Laika like the garden :)
12 Correct 13 ms 5332 KB Correct! Azusa and Laika like the garden :)
13 Correct 11 ms 5276 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5460 KB Correct! Azusa and Laika like the garden :)
2 Incorrect 3 ms 4948 KB Unexpected end of file - token expected
3 Halted 0 ms 0 KB -