Submission #632526

# Submission time Handle Problem Language Result Execution time Memory
632526 2022-08-20T09:42:06 Z boris_mihov Gardening (RMI21_gardening) C++17
0 / 100
21 ms 5580 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <queue>

typedef long long llong;
const int MAXN = 200000 + 10;
const int INF  = 1e9;

int n, m, k;
int sx, sy, ex, ey, curr;
std::vector <int> t[MAXN];
void putFrame()
{
    for (int i = sx ; i <= ex ; ++i)
    {
        t[i][sy] = curr;
        t[i][ey] = curr;
    }

    for (int i = sy ; i <= ey ; ++i)
    {
        t[sx][i] = curr;
        t[ex][i] = curr;
    }

    sx++;
    sy++;
    ex--;
    ey--;
    curr++;
}

void putRow()
{
    for (int i = sy ; i <= ey ; ++i)
    {
        t[sx][i] = curr;
        t[sx + 1][i] = curr;
    }

    sx += 2;
    curr++;
}

void putCol()
{
    for (int i = sx ; i <= ex ; ++i)
    {
        t[i][sy] = curr;
        t[i][sy + 1] = curr;
    }

    sy += 2;
    curr++;
}

void solve()
{
    if (n&1 || m&1)
    {
        std::cout << "NO\n";
        return;
    }

    if (k < std::min(n/2, m/2) || n/2 + m/2 <= k)
    {
        std::cout << "NO\n";
        return;
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        t[i].clear();
        t[i].resize(m + 1);
    }

    int realN = n;
    int realM = m;
    sx = 1;
    sy = 1;
    ex = n;
    ey = m;
    curr = 1;

    while (k >= 1)
    {
        if (k == std::min(n/2, m/2)) 
        {
            putFrame();
            n -= 2;
            m -= 2;
            k--;
            continue;
        }

        if (n >= m) 
        {
            putRow();
            n -= 2;
            k--;
            continue;
        }

        if (m > n) 
        {
            putCol();
            m -= 2;
            k--;
            continue;
        }
    }

    std::cout << "YES\n";
    for (int i = 1 ; i <= realN ; ++i)
    {
        for (int j = 1 ; j <= realM ; ++j)
        {
            std::cout << t[i][j] << ' ';
        }

        std::cout << '\n';
    }
}

void read()
{
    std::cin >> n >> m >> k;
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int tests;
int main()
{
    fastIO();
    std::cin >> tests;

    while (tests--)
    {
        read();
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Failed 21 ms 5580 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 21 ms 5580 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 21 ms 5580 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 4 ms 5076 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 4 ms 5016 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 21 ms 5580 KB Incorrect output
2 Halted 0 ms 0 KB -