Submission #1211616

#TimeUsernameProblemLanguageResultExecution timeMemory
1211616Ghulam_JunaidGardening (RMI21_gardening)C++20
11 / 100
60 ms832 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 22, M = 2e5 + 10;
int n, m, k, mat[N][M];

void color22(int i, int j, int c){
    mat[i][j] = mat[i][j + 1] = c;
    mat[i + 1][j] = mat[i + 1][j + 1] = c;
}

void solve(){
    cin >> n >> m >> k;
    if (n % 2 or m % 2 or k > (1ll * n * m) / 4){
        cout << "NO" << endl;
        return ;
    }

    if (n == 2){
        if (k != m / 2){
            cout << "NO" << endl;
            return ;
        }

        for (int i = 1; i <= m; i += 2)
            color22(1, i, 1 + i / 2);
    }

    if (n == 4){
        bool done = 0;
        for (int c = 4; c <= m; c += 2){
            int kk = 1 + (c - 2) / 2 + m - c;
            if (k != kk) continue;
            done = 1;

            int cur = 1;
            for (int i = 2; i < c; i += 2){
                color22(2, i, cur);
                cur++;
            }
            for (int i = c + 1; i < m; i += 2){
                color22(1, i, cur);
                cur++;
                color22(3, i, cur);
                cur++;
            }

            for (int i = 1; i <= c; i ++)
                mat[1][i] = mat[4][i] = cur;
            mat[1][1] = mat[2][1] = mat[3][1] = mat[4][1] = cur;
            mat[1][c] = mat[2][c] = mat[3][c] = mat[4][c] = cur;
            break;
        }

        if (k == (n * m) / 4){
            int cur = 1;
            for (int i = 1; i < m; i += 2){
                color22(1, i, cur);
                cur++;
                color22(3, i, cur);
                cur++;
            }
            done = 1;
        }

        if (!done){
            cout << "NO" << endl;
            return ;
        }
    }

    cout << "YES" << endl;
    for (int i = 1; i <= n; i ++){
        for (int j = 1; j <= m; j ++)
            cout << mat[i][j] << " ";
        cout << endl;
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t;
    cin >> t;

    while (t--)
        solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...