답안 #856668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856668 2023-10-04T09:08:40 Z iulia_morariu Gardening (RMI21_gardening) C++14
5 / 100
96 ms 800 KB
#include <bits/stdc++.h>

using namespace std;

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

    //1.
    int n, m, t, k;

    //2.
    cin >> t;

    //3.
    for(int ii = 0; ii < t; ii++){
        cin >> n >> m >> k;

        if(n % 2 == 1 || m % 2 == 1){
            cout << "NO" << endl;
            continue;
        }

        if(n == 2 && m == 2 && k == 1){
            cout << "YES" << endl;
            cout << "1 1" << endl;
            cout << "1 1" << endl;
            continue;
        }

        if(n == 2 && m == 4 && k == 2){
            cout << "YES" << endl;
            cout << "1 1 2 2" << endl;
            cout << "1 1 2 2" << endl;
            continue;
        }

        if(n == 4 && m == 2 && k == 2){
            cout << "YES" << endl;
            cout << "1 1" << endl;
            cout << "1 1" << endl;
            cout << "2 2" << endl;
            cout << "2 2" << endl;
            continue;
        }

        if(n == 4 && m == 4 && k == 2){
            cout << "YES" << endl;
            cout << "1 1 1 1" << endl;
            cout << "1 2 2 1" << endl;
            cout << "1 2 2 1" << endl;
            cout << "1 1 1 1" << endl;
            continue;
        }

        if(n == 4 && m == 4 && k == 4){
            cout << "YES" << endl;
            cout << "1 1 2 2" << endl;
            cout << "1 1 2 2" << endl;
            cout << "3 3 4 4" << endl;
            cout << "3 3 4 4" << endl;
            continue;
        }


        if(n == 2 && m / 2 == k){
            cout << "YES" << endl;
            int it = 0;
            for(int i = 0; i < m; i++){
                if(i % 2 == 0) it++;
                cout << it << " ";
            }
            cout << endl;
            it = 0;
            for(int i = 0; i < m; i++){
                if(i % 2 == 0) it++;
                cout << it << " ";
            }
            cout << endl;
            continue;
        }

        if(m <= 4 && n <= 4){
            cout << "NO" << endl;
            continue;
        }

        if(n != 4){
            cout << "NO" << endl;
            continue;
        }

        int v[n][m];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++) v[i][j] = 0;
        }

        int m1 = m;
        int cate = INT_MAX;
        for(int it = 0; it <= k; it += 2){
            if( (m1 - 2) / 2 + it + 1 == k ){
                cate = it;
                break;
            }
            m1 -= 2;
        }

        if(cate == INT_MAX){
            cout << "NO" << endl;
            continue;
        }

        //cout << "punem de la inceput " << cate << endl;

        int it = 0;
        if(cate > 0){
            for(int i = 0; i < cate; i++){
                if(i % 2 == 0) it++;
                v[0][i] = it;
                v[1][i] = it;
            }
            for(int i = 0; i < cate; i++){
                if(i % 2 == 0) it++;
                v[2][i] = it;
                v[3][i] = it;
            }
        }
        it++;
        for(int i = cate; i < m; i++){
            v[0][i] = it;
            v[3][i] = it;
        }
        v[1][cate] = it;
        v[2][cate] = it;

        v[1][m - 1] = it;
        v[2][m - 1] = it;

        for(int i = cate + 1; i < m - 1; i++){
            //cout << "i = " << i << " it = " << it << endl;
            if( (i - (cate + 1)) % 2 == 0 ) it++;
            v[1][i] = it;
            v[2][i] = it;
        }

        bool ok = 1;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                int cnt = 0;
                if(i > 0 && v[i - 1][j] == v[i][j]) cnt++;
                if(i < n - 1 && v[i + 1][j] == v[i][j]) cnt++;
                if(j > 0 && v[i][j] == v[i][j - 1]) cnt++;
                if(j + 1 < m && v[i][j] == v[i][j + 1]) cnt++;

                if(cnt != 2 || v[i][j] > k){
                    ok = 0;
                }
            }
        }

        if(!ok){
            cout << "NO" << endl;
            continue;
        }

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


    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 800 KB Correct! Azusa and Laika like the garden :)
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 800 KB Correct! Azusa and Laika like the garden :)
2 Failed 16 ms 604 KB Incorrect output
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 800 KB Correct! Azusa and Laika like the garden :)
2 Failed 16 ms 604 KB Incorrect output
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 348 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 348 KB Incorrect output
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 800 KB Correct! Azusa and Laika like the garden :)
2 Failed 16 ms 604 KB Incorrect output
3 Halted 0 ms 0 KB -