답안 #645090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645090 2022-09-26T08:44:14 Z Vanilla Gardening (RMI21_gardening) C++17
0 / 100
22 ms 724 KB
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
int n,m,k;

bool build (int i1, int j1, int i2, int j2, vector <vector <int> >& a, int k) {
    int can = (i2 - i1 + 1) * (j2 - j1 + 1) / 4;
    // cout << i1 << " " << j1 << " " << i2 << " " << j2 << " " << k << " " << can << "\n";
    if (!can) return (!k);
    if (can > k) {
        for (int j = j1; j <= j2; j++){
            a[i1][j] = a[i2][j] = k;
        }
        for (int i = i1; i <= i2; i++){
            a[i][j1] = a[i][j2] = k;
        }
        return build(i1 + 1, j1 + 1, i2 - 1, j2 - 1, a, k - 1);
    }
    else if (can == k){
        for (int i = i1; i < i2; i+=2){
            for (int j = j1; j < j2; j+=2){
                a[i][j] = a[i][j+1] = a[i+1][j] = a[i+1][j+1] = k--;
            }
        }
        return 1;
    }
    return 0;
}

bool build2 (int i1, int j1, int i2, int j2, vector <vector <int> >& a, int k) {
    int can = (i2 - i1 + 1) * (j2 - j1 + 1) / 4;
    // cout << i1 << " " << j1 << " " << i2 << " " << j2 << " " << k << " " << can << "\n";
    if (!can) return (!k);
    if (can > k) {
        for (int j = j1; j <= j2; j++){
            a[i1][j] = a[i2][j] = k;
        }
        for (int i = i1; i <= i2; i++){
            a[i][j1] = a[i][j2] = k;
        }
        return build2(i1 + 1, j1 + 1, i2 - 1, j2 - 1, a, k - 1);
    }
    else if (can == k){
        for (int i = i1; i < i2; i+=2){
            for (int j = j1; j < j2; j+=2){
                a[i][j] = a[i][j+1] = a[i+1][j] = a[i+1][j+1] = k--;
            }
        }
        return 1;
    }
    return 0;
}

void solve() {
    cin >> n >> m >> k;
    if (n % 2 || m % 2) {
        cout << "NO\n";
        return;
    }
    if (n == m) {
        vector <vector <int> > a (n, vector <int> (m));
        if (build (0, 0, n - 1, n - 1, a, k)) {
            cout << "YES\n";
            for (auto i: a) {
                for (auto j: i) {
                    cout << j << " ";
                }
                cout << "\n";
            }
        }
        else {
            cout << "NO\n";
        }
    }
    else {
        vector <vector <int> > a (n, vector <int> (m));
        if (build2 (0, 0, n - 1, m - 1, a, k)) {
            cout << "YES\n";
            for (auto i: a) {
                for (auto j: i) {
                    cout << j << " ";
                }
                cout << "\n";
            }
        }
        else {
            cout << "NO\n";
        }
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Failed 22 ms 724 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 22 ms 724 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 22 ms 724 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 340 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 340 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 22 ms 724 KB Incorrect output
2 Halted 0 ms 0 KB -