Submission #685463

# Submission time Handle Problem Language Result Execution time Memory
685463 2023-01-24T12:03:58 Z QwertyPi Gardening (RMI21_gardening) C++14
11 / 100
118 ms 696 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

int a[200000];
void solve(){
    int N, M, K; cin >> N >> M >> K;
    if(N % 2 == 1 || M % 2 == 1 || K > N * M / 4 || K < max(N, M) / 2) {
        cout << "NO" << endl;
        return;
    }
    if(N == 2){
        if(K != M / 2){
            cout << "NO" << endl;
        }else{
            cout << "YES" << endl;
            for(int i = 0; i < N; i++){
                for(int j = 0; j < M; j++){
                    cout << j / 2 + 1 << ' ';
                }
                cout << endl;
            }
        }
        return;
    }
    
    if(M == 2){
        if(K != N / 2){
            cout << "NO" << endl;
        }else{
            cout << "YES" << endl;
            for(int i = 0; i < N; i++){
                for(int j = 0; j < M; j++){
                    cout << i / 2 + 1 << ' ';
                }
                cout << endl;
            }
        }
        return;
    }
    
    int x1 = 0, x2 = N - 1, y1 = 0, y2 = M - 1;
    while(K > 0){
        // cout << x2 - x1 + 1 << ' ' << y2 - y1 + 1 << ' ' << K << endl;
        if(x2 - x1 + 1 >= 6 && y2 - y1 + 1 >= 6 && K - 1 <= (x2 - x1 - 1) * (y2 - y1 - 1) / 4 || x2 - x1 + 1 >= 4 && y2 - y1 + 1 >= 4 && K - 1 == (x2 - x1 - 1) * (y2 - y1 - 1) / 4){
            for(int x = x1; x <= x2; x++){
                a[x * M + y1] = a[x * M + y2] = K;
            }
            for(int y = y1; y <= y2; y++){
                a[x1 * M + y] = a[x2 * M + y] = K;
            }
            K--; x1++; x2--; y1++; y2--;
        }else if(x2 - x1 + 1 >= 6 && x2 - x1 + 1 >= y2 - y1 + 1 && K - (y2 - y1 + 1) / 2 >= max(x2 - x1 - 1, y2 - y1 + 1) / 2){
            for(int y = y1; y <= y2; y++){
                a[x1 * M + y] = a[(x1 + 1) * M + y] = K - (y - y1) / 2;
            }
            K -= (y2 - y1 + 1) / 2; x1 += 2;
        }else if(y2 - y1 + 1 >= 6 && y2 - y1 + 1 >= x2 - x1 + 1 && K - (x2 - x1 + 1) / 2 >= max(x2 - x1 + 1, y2 - y1 - 1) / 2){
            for(int x = x1; x <= x2; x++){
                a[x * M + y1] = a[x * M + (y1 + 1)] = K - (x - x1) / 2;
            }
            K -= (x2 - x1 + 1) / 2; y1 += 2;
        }else if(x2 - x1 + 1 == 4 && y2 - y1 + 1 == 4){
            if(K == 4){
                for(int x = x1; x <= x2; x++){
                    for(int y = y1; y <= y2; y++){
                        a[x * M + y] = (x - x1) / 2 * 2 + (y - y1) / 2 + 1;
                    }
                }
                K -= 4;
            }else if(K == 2){
                for(int x = x1; x <= x2; x++){
                    for(int y = y1; y <= y2; y++){
                        a[x * M + y] = 1;
                    }
                }
                for(int x = x1 + 1; x <= x2 - 1; x++){
                    for(int y = y1 + 1; y <= y2 - 1; y++){
                        a[x * M + y] = 2;
                    }
                }
                K -= 2;
            }else{
                cout << "NO" << endl;
                return;
            }
        }else if(x2 - x1 + 1 == 2){
            assert(K == (y2 - y1 + 1) / 2);
            for(int y = y1; y <= y2; y++){
                a[x1 * M + y] = (y - y1) / 2 + 1;
                a[(x1 + 1) * M + y] = (y - y1) / 2 + 1;
            }
            K -= (y2 - y1 + 1);
        }else if(y2 - y1 + 1 == 2){
            assert(K == (x2 - x1 + 1) / 2);
            for(int x = x1; x <= x2; x++){
                a[x * M + y1] = (x - x1) / 2 + 1;
                a[x * M + y1 + 1] = (x - x1) / 2 + 1;
            }
            K -= (x2 - x1 + 1);
        }
    }
    cout << "YES" << endl;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            cout << a[i * M + j] << ' ';
        }
        cout << endl;
    }
}

int32_t main(){
    int T; cin >> T;
    while(T--){
        solve();
    }
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:45:49: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   45 |         if(x2 - x1 + 1 >= 6 && y2 - y1 + 1 >= 6 && K - 1 <= (x2 - x1 - 1) * (y2 - y1 - 1) / 4 || x2 - x1 + 1 >= 4 && y2 - y1 + 1 >= 4 && K - 1 == (x2 - x1 - 1) * (y2 - y1 - 1) / 4){
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 118 ms 696 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 118 ms 696 KB Correct! Azusa and Laika like the garden :)
2 Correct 20 ms 596 KB Correct! Azusa and Laika like the garden :)
3 Correct 21 ms 612 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 118 ms 696 KB Correct! Azusa and Laika like the garden :)
2 Correct 20 ms 596 KB Correct! Azusa and Laika like the garden :)
3 Correct 21 ms 612 KB Correct! Azusa and Laika like the garden :)
4 Failed 21 ms 596 KB Incorrect output
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 18 ms 616 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 5 ms 424 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 696 KB Correct! Azusa and Laika like the garden :)
2 Correct 20 ms 596 KB Correct! Azusa and Laika like the garden :)
3 Correct 21 ms 612 KB Correct! Azusa and Laika like the garden :)
4 Failed 21 ms 596 KB Incorrect output
5 Halted 0 ms 0 KB -