답안 #923963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923963 2024-02-08T07:03:29 Z GrindMachine Gardening (RMI21_gardening) C++17
100 / 100
18 ms 1116 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*



*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

ll f(ll n, ll m){
    return max(n/2,m/2);
}

ll g(ll n, ll m){
    return (n/2)*(m/2);
}

vector<vector<ll>> a;
ll ptr;
bool ok;

void go(ll li, ll ri, ll lj, ll rj, ll k){
    ll n = ri-li+1;
    ll m = rj-lj+1;
    if(n == 0 and m == 0){
        if(k) ok = false;
        return;
    }

    // place on border
    if(f(n-2,m-2) <= k-1 and k-1 <= g(n-2,m-2) and k-1 != g(n-2,m-2)-1){
        ptr++;
        for(int j = lj; j <= rj; ++j){
            a[li][j] = a[ri][j] = ptr;
        }
        for(int i = li; i <= ri; ++i){
            a[i][lj] = a[i][rj] = ptr;
        }
        go(li+1,ri-1,lj+1,rj-1,k-1);
        return;
    }

    // split by row
    for(int i = 2; i < n; i += 2){
        ll mnl = f(i,m), mxl = g(i,m);
        ll mnr = f(n-i,m), mxr = g(n-i,m);
        if(mnl+mnr <= k and k <= mxl+mxr){
            for(int k1 = mnl; k1 <= mxl; ++k1){
                ll k2 = k-k1;
                if(k2 >= mnr and k2 <= mxr and k1 != mxl-1 and k2 != mxr-1){
                    go(li,li+i-1,lj,rj,k1);
                    go(li+i,ri,lj,rj,k2);
                    return;
                }
            }
        }
    }

    // split by col
    for(int j = 2; j < m; j += 2){
        ll mnl = f(n,j), mxl = g(n,j);
        ll mnr = f(n,m-j), mxr = g(n,m-j);
        if(mnl+mnr <= k and k <= mxl+mxr){
            for(int k1 = mnl; k1 <= mxl; ++k1){
                ll k2 = k-k1;
                if(k2 >= mnr and k2 <= mxr and k1 != mxl-1 and k2 != mxr-1){
                    go(li,ri,lj,lj+j-1,k1);
                    go(li,ri,lj+j,rj,k2);
                    return;
                }
            }
        }
    }

    ok = false;
}

void solve(int test_case)
{
    ll n,m,k; cin >> n >> m >> k;
    if((n&1) or (m&1)){
        no;
        return;
    }

    if(!(f(n,m) <= k and k <= g(n,m))){
        no;
        return;
    }

    if(k == g(n,m)-1){
        no;
        return;
    }

    a = vector<vector<ll>>(n+5,vector<ll>(m+5));
    ptr = 0;
    ok = true;
    go(1,n,1,m,k);

    if(!ok){
        no;
        return;
    }

    yes;

    rep1(i,n){
        rep1(j,m){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

int main()
{
    fastio;

    int t = 1;
    cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 848 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 848 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 848 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 824 KB Correct! Azusa and Laika like the garden :)
2 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 7 ms 856 KB Correct! Azusa and Laika like the garden :)
5 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
6 Correct 6 ms 860 KB Correct! Azusa and Laika like the garden :)
7 Correct 7 ms 860 KB Correct! Azusa and Laika like the garden :)
8 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
9 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
10 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
11 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
12 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
13 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
2 Correct 2 ms 604 KB Correct! Azusa and Laika like the garden :)
3 Correct 2 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 4 ms 600 KB Correct! Azusa and Laika like the garden :)
5 Correct 4 ms 604 KB Correct! Azusa and Laika like the garden :)
6 Correct 2 ms 604 KB Correct! Azusa and Laika like the garden :)
7 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
8 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
9 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
10 Correct 4 ms 604 KB Correct! Azusa and Laika like the garden :)
11 Correct 2 ms 600 KB Correct! Azusa and Laika like the garden :)
12 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
13 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
14 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
15 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
16 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
17 Correct 3 ms 600 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 848 KB Correct! Azusa and Laika like the garden :)
2 Correct 11 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 8 ms 604 KB Correct! Azusa and Laika like the garden :)
6 Correct 7 ms 824 KB Correct! Azusa and Laika like the garden :)
7 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
8 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
9 Correct 7 ms 856 KB Correct! Azusa and Laika like the garden :)
10 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
11 Correct 6 ms 860 KB Correct! Azusa and Laika like the garden :)
12 Correct 7 ms 860 KB Correct! Azusa and Laika like the garden :)
13 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
14 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
15 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
16 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
17 Correct 6 ms 604 KB Correct! Azusa and Laika like the garden :)
18 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
19 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
20 Correct 2 ms 604 KB Correct! Azusa and Laika like the garden :)
21 Correct 2 ms 604 KB Correct! Azusa and Laika like the garden :)
22 Correct 4 ms 600 KB Correct! Azusa and Laika like the garden :)
23 Correct 4 ms 604 KB Correct! Azusa and Laika like the garden :)
24 Correct 2 ms 604 KB Correct! Azusa and Laika like the garden :)
25 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
26 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
27 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
28 Correct 4 ms 604 KB Correct! Azusa and Laika like the garden :)
29 Correct 2 ms 600 KB Correct! Azusa and Laika like the garden :)
30 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
31 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
32 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
33 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
34 Correct 3 ms 604 KB Correct! Azusa and Laika like the garden :)
35 Correct 3 ms 600 KB Correct! Azusa and Laika like the garden :)
36 Correct 12 ms 856 KB Correct! Azusa and Laika like the garden :)
37 Correct 10 ms 856 KB Correct! Azusa and Laika like the garden :)
38 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
39 Correct 10 ms 856 KB Correct! Azusa and Laika like the garden :)
40 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
41 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
42 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
43 Correct 10 ms 856 KB Correct! Azusa and Laika like the garden :)
44 Correct 9 ms 856 KB Correct! Azusa and Laika like the garden :)
45 Correct 9 ms 856 KB Correct! Azusa and Laika like the garden :)
46 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
47 Correct 10 ms 856 KB Correct! Azusa and Laika like the garden :)
48 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
49 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
50 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
51 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
52 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
53 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
54 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
55 Correct 9 ms 860 KB Correct! Azusa and Laika like the garden :)
56 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
57 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)
58 Correct 10 ms 1116 KB Correct! Azusa and Laika like the garden :)
59 Correct 10 ms 872 KB Correct! Azusa and Laika like the garden :)
60 Correct 10 ms 860 KB Correct! Azusa and Laika like the garden :)