Submission #645098

# Submission time Handle Problem Language Result Execution time Memory
645098 2022-09-26T09:17:50 Z Vanilla Gardening (RMI21_gardening) C++17
0 / 100
20 ms 696 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 t1 (int i1, int j1, int i2, int j2, vector <vector <int> >& a, int 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--;
        }
    }
}

void t2 (int i1, int j1, int i2, int j2, vector <vector <int> >& a, int k) {
    if (i1 >= i2) return;
    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;
    }
    t2(i1 + 1, j1 + 1, i2 - 1, j2 - 1, a, k - 1);
}


void solve() {
    cin >> n >> m >> k;
    if (n % 2 || m % 2) {
        cout << "NO\n";
        return;
    }
    vector <vector <int> > a (n, vector <int> (m));
    if (n == 2) {
        if (n * m / 4 == k) {
            t2(0, 0, n - 1, m - 1, a, k);
        }
        else {
            cout << "NO\n";
            return;
        }
    }
    else if (n == 4) {
        // n <= 4
        int pot = n * m / 4;
        int f = -2;
        if (pot == k) f = -1;
        for (int i = 3; i < m; i+=3){
            if (pot - 2 == k) {
                f = i;
                break;
            }
            pot-=2;
        }
        if (f == -2) {
            cout << "NO\n";
            return;
        }
        for (int p = 0; p < f; p+=4){
            t2(0, p, n - 1, p + 3, a, k);
            k-=2;
        }
        t1(0, f + 1, n - 1, m - 1, a, k);
    }
    cout << "YES\n";
    for (auto i: a) {
        for (auto j: i) {
            cout << j << " ";
        }
        cout << "\n";
    }
    // 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();
}
# Verdict Execution time Memory Grader output
1 Failed 20 ms 652 KB Output does not contain all values between 1 and k
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 20 ms 652 KB Output does not contain all values between 1 and k
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 20 ms 652 KB Output does not contain all values between 1 and k
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 12 ms 596 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 13 ms 696 KB Output contains values not between 1 and k
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 20 ms 652 KB Output does not contain all values between 1 and k
2 Halted 0 ms 0 KB -