답안 #1066723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1066723 2024-08-20T05:45:22 Z 정민찬(#11123) Gardening (RMI21_gardening) C++17
11 / 100
12 ms 860 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

vector<vector<int>> a;

int pv;
bool flag;

void go(int sx, int sy, int h, int w, int K) {
    if (K == h * w / 4 - 1) {
        flag = false;
        return;
    }
    if (K == h * w / 4) {
        for (int x=sx; x<sx+h; x+=2) {
            for (int y=sy; y<sy+w; y+=2) {
                a[x][y] = a[x+1][y] = a[x][y+1] = a[x+1][y+1] = ++ pv;
            }
        }
        return;
    }
    if (h == 2 || w == 2) {
        flag = false;
        return;
    }
    int red = h / 2 + w / 2 - 2;
    int diff = h * w / 4 - K;
    int nh = 4, nw = 4, nk;
    if (diff <= red) {
        if (h / 2 <= diff) {
            nh = h;
            nw = 4 + (diff - h / 2) * 2;
        }
        else nh = diff * 2;
        nk = (nh-2) * (nw-2) / 4;
    }
    else if (diff == red + 1) {
        if (h >= 6 && w >= 8) {
            nh = h;
            nw = w - 2;
        }
        else if (h >= 8 && w >= 6) {
            nh = h - 2;
            nw = w;
        }
        else {
            flag = false;
            return;
        }
        nk = (nh-2) * (nw-2) / 4 - 2;
    }
    else {
        nh = h;
        nw = w;
        nk = K - red - 1;
    }
    pv ++;
    for (int i=0; i<nh; i++) {
        a[sx + i][sy] = pv;
        a[sx + i][sy + nw - 1] = pv;
    }
    for (int i=0; i<nw; i++) {
        a[sx][sy + i] = pv;
        a[sx + nh - 1][sy + i] = pv;
    }
    go(sx + 1, sy + 1, nh - 2, nw - 2, nk);
    for (int x=sx; x<sx+h; x+=2) {
        for (int y=sy; y<sy+w; y+=2) {
            if (x < sx + nh && y < sy + nw) continue;
            a[x][y] = a[x+1][y] = a[x][y+1] = a[x+1][y+1] = ++ pv;
        }
    }
}

void run_case() {
    ll n, m, k;
    cin >> n >> m >> k;
    if (n % 2 || m % 2) {
        cout << "NO\n";
        return;
    }
    if (k > n*m/4) {
        cout << "NO\n";
        return;
    }
    a.assign(n, vector<int>(m, 0));
    pv = 0;
    flag = true;
    go(0, 0, n, m, k);
    if (!flag) {
        cout << "NO\n";
        return;
    }
    cout << "YES\n";
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            cout << a[i][j] << ' ';
        }
        cout << '\n';
    }
}

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    int tc;
    cin >> tc;
    while (tc --) {
        run_case();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 856 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 856 KB Correct! Azusa and Laika like the garden :)
2 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 860 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 856 KB Correct! Azusa and Laika like the garden :)
2 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 860 KB Correct! Azusa and Laika like the garden :)
4 Failed 6 ms 600 KB Incorrect output
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 2 ms 348 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 348 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 856 KB Correct! Azusa and Laika like the garden :)
2 Correct 6 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 860 KB Correct! Azusa and Laika like the garden :)
4 Failed 6 ms 600 KB Incorrect output
5 Halted 0 ms 0 KB -