Submission #850865

# Submission time Handle Problem Language Result Execution time Memory
850865 2023-09-17T14:59:09 Z Itamar Gardening (RMI21_gardening) C++14
21 / 100
15 ms 860 KB
// garden.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>

bool pos(int l1,int r1, int l2,int r2, int k,int c, vector<vi>& ans) {
    int n = (r1 - l1 + 1), m = (r2 - l2 + 1);
    if (n <= 0 || m <= 0)return 1;
    if ((n==6 && m==6 && k==4)||n % 2 || m % 2 || 4 * k > n * m || k == ((n * m) / 4) - 1 || k < max(n / 2, m / 2) || (min(n, m) == 2 && k != max(n, m) / 2)) {
        return 0;
    }
    for (int i = l1; i <= r1; i++) {
        for (int j = l2; j <= l2 + 1; j++) {
            ans[i][j] = c + (i - l1) / 2;
        }
    }
    l2 += 2;
    k -= n / 2;
    c += n / 2;
    if (pos(l1, r1, l2, r2, k, c, ans))return 1;
    l2 -= 2;
    k += n / 2;
    c -= n / 2;
    for (int i = l1; i <= l1 + 1; i++) {
        for (int j = l2; j <= r2; j++) {
            ans[i][j] = c + (j - l2) / 2;
        }
    }
    l1 += 2;
    k -= m / 2;
    c += m / 2;
    if (pos(l1, r1, l2, r2, k, c, ans))return 1;
    l1 -= 2;
    k += m / 2;
    c -= m / 2;
    for (int i = l1; i <= r1; i++) {
        ans[i][l2] = c;
        ans[i][r2] = c;
    }
    for (int j = l2; j <= r2; j++) {
        ans[l1][j] = c;
        ans[r1][j] = c;
    }
    k--, c++, l1++, l2++, r1--, r2--;
    return pos(l1, r1, l2, r2, k, c, ans);
}

int main()
{
    int t;
    cin >> t;
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    for (int i = 0; i < t; i++) {
        int n, m, k;
        cin >> n >> m >> k;
        if ((n == 6 && m == 6 && k == 4) || n % 2 || m % 2 || 4 * k > n * m || k == ((n * m) / 4) - 1 || k < max(n / 2, m / 2) || (min(n, m) == 2 && k != max(n, m) / 2)) {
            cout << "NO" << "\n";
            continue;
        }
        cout << "YES" << "\n";
        vector<vi> ans(n, vi(m));
        ans.resize(n, vi(m));
        pos(0,n-1,0, m-1, k, 1,ans);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cout << ans[i][j];
                if (j < m - 1)cout << ' ';
                else cout << "\n"; 
            }
        }
    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Failed 10 ms 860 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 Failed 3 ms 600 KB Incorrect output
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 600 KB Correct! Azusa and Laika like the garden :)
3 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
4 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
5 Correct 7 ms 604 KB Correct! Azusa and Laika like the garden :)
6 Failed 10 ms 860 KB Incorrect output
7 Halted 0 ms 0 KB -