답안 #850854

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850854 2023-09-17T14:37:42 Z Itamar Gardening (RMI21_gardening) C++14
5 / 100
16 ms 856 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==m && k == n+1)||n % 2 || m % 2 || 4 * k > n * m || k < max(n/2, m/2) || (min(n, m) == 2 && k != max(n, m) / 2) || (n == 4 && m == 4 && k == 3)) {
        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 % 2 || m % 2 || 4 * k > n * m || k < max(n/2, m/2) || (min(n, m) == 2 && k != max(n, m) / 2) || (n == 4 && m == 4 && k == 3)) {
            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
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 604 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 604 KB Correct! Azusa and Laika like the garden :)
2 Failed 8 ms 776 KB Incorrect output
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 604 KB Correct! Azusa and Laika like the garden :)
2 Failed 8 ms 776 KB Incorrect output
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 8 ms 856 KB Output contains flowers without two equal neighbours
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 3 ms 604 KB Output contains disconnected flowers of the same kind
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 604 KB Correct! Azusa and Laika like the garden :)
2 Failed 8 ms 776 KB Incorrect output
3 Halted 0 ms 0 KB -