Submission #645089

# Submission time Handle Problem Language Result Execution time Memory
645089 2022-09-26T08:30:01 Z Vanilla Gardening (RMI21_gardening) C++17
0 / 100
14 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 == 0) return 0;
    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;
    }
    else return 0;
}

void solve() {
    cin >> n >> m >> k;
    if (n == m) {
        if (n % 2 == 1) {
            cout << "NO\n";
            return;
        }
        vector <vector <int> > a (n, vector <int> (n));
        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 {
        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 14 ms 724 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 14 ms 724 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 14 ms 724 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 1 ms 340 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 1 ms 340 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 14 ms 724 KB Incorrect output
2 Halted 0 ms 0 KB -