Submission #632531

# Submission time Handle Problem Language Result Execution time Memory
632531 2022-08-20T09:53:51 Z boris_mihov Gardening (RMI21_gardening) C++17
0 / 100
28 ms 5716 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(int count)
{
    for (int i = 0 ; i <= count-2 ; ++i)
    {
        t[sx][sy + 2*i] = curr;
        t[sx][sy + 2*i + 1] = curr;
        t[sx + 1][sy + 2*i] = curr;
        t[sx + 1][sy + 2*i + 1] = curr;
        curr++;
    }

    for (int i = sy + 2*(count-1) ; i <= ey ; ++i)
    {
        t[sx][i] = curr;
        t[sx + 1][i] = curr;
    }

    sx += 2;
    curr++;
}

void putCol(int count)
{
    for (int i = 0 ; i <= count-2 ; ++i)
    {
        t[sx + 2*i][sy] = curr;
        t[sx + 2*i + 1][sy] = curr;
        t[sx + 2*i][sy + 1] = curr;
        t[sx + 2*i + 1][sy + 1] = curr;
        curr++;
    }

    for (int i = sx + 2*(count-1) ; 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*m/4 < 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) 
        {
            int newK = k - std::min(k - std::min((n-2)/2, m/2), (ey - sy + 1) / 2);
            putRow(std::min(k - std::min((n-2)/2, m/2), (ey - sy + 1) / 2));
            n -= 2;
            k = newK;
            continue;
        }

        if (m > n) 
        {
            int newK = k - std::min(k - std::min(n/2, (m-2)/2), (ex - sx + 1) / 2);
            putCol(std::min(k - std::min(n/2, (m-2)/2), (ex - sx + 1) / 2));
            m -= 2;
            k = newK;
            continue;
        }
    }

    std::cout << "YES\n";
    for (int i = 1 ; i <= realN ; ++i)
    {
        for (int j = 1 ; j <= realM ; ++j)
        {
            if (t[i][j] < 10) std::cout << 0;
            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 Incorrect 28 ms 5716 KB Expected integer, but "01" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 5716 KB Expected integer, but "01" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 5716 KB Expected integer, but "01" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 5464 KB Expected integer, but "01" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5076 KB Expected integer, but "01" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 5716 KB Expected integer, but "01" found
2 Halted 0 ms 0 KB -