Submission #770787

# Submission time Handle Problem Language Result Execution time Memory
770787 2023-07-02T00:07:47 Z gg123_pe Gardening (RMI21_gardening) C++14
11 / 100
17 ms 724 KB
#include <bits/stdc++.h> 
using namespace std; 

#define f(i,a,b) for(int i = a; i < b; i++)

bool fe; 
int c; 

pair<int,int> range(int n, int m){
    if(n == 2) return {m/2, m/2}; 
    return {n*m/4 - m/2, n*m/4}; 
}

void print(vector <vector<int>> v){
    int n = v.size(), m = v[0].size(); 
    if(!fe){
        f(i,0,n) { f(j,0,m) cout << ((v[i][j] == 0) ? c : v[i][j]) << " "; cout << "\n"; }
    }
    else{
        f(i,0,m) { f(j,0,n) cout << ((v[j][i] == 0) ? c : v[j][i]) << " "; cout << "\n"; }
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t; cin >> t; 
    while(t--){
        int n, m, k; 
        cin >> n >> m >> k; 

        if(n&1 or m&1){
            cout << "NO\n";
            continue;  
        }
        fe = 0; 
        if(n > m) {
            fe = 1; 
            swap(n, m); 
        }

        pair<int,int> p = range(n, m); 
        if(p.second < k or k < p.first){
            cout << "NO\n"; 
            continue; 
        }
    
        vector <vector<int>> v(n, vector <int> (m)); 
        bool ra = 0; 

        if(n == 2){
            c = 1; 
            for(int i = 0; i < m; i += 2){
                v[0][i] = v[0][i+1] = c; 
                v[1][i] = v[1][i+1] = c; 
                c++; 
            }
        }
        else{   
            c = 1; 
            for(int i = 0; i < n-4; i += 2){
                for(int j = 0; j < m; j += 2){
                    v[i][j] = v[i][j+1] = c; 
                    v[i+1][j] = v[i+1][j+1] = c; 
                    c++; 
                    k--; 
                }
            }
            int L = 2*k - m;
            if(m - L < 4 and m - L > 0){
                cout << "NO\n"; 
                ra = 1; 
            } 
            for(int i = 0; i < L; i += 2){
                f(r, n-4, n-2) f(s, i, i+2) v[r][s] = c; 
                c++; 
                f(r, n-2, n) f(s, i, i+2) v[r][s] = c; 
                c++; 
            }
            for(int i = L+1; i < m-1; i += 2){
                f(r, n-3, n-1) f(s, i, i+2) v[r][s] = c; 
                c++; 
            }
        }
        if(!ra){
            cout << "YES\n"; 
            print(v); 
        }
    }
    return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 724 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 17 ms 724 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
# Verdict Execution time Memory Grader output
1 Correct 17 ms 724 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Failed 9 ms 640 KB Incorrect output
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 1 ms 340 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 1 ms 340 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 724 KB Correct! Azusa and Laika like the garden :)
2 Correct 8 ms 588 KB Correct! Azusa and Laika like the garden :)
3 Correct 8 ms 596 KB Correct! Azusa and Laika like the garden :)
4 Failed 9 ms 640 KB Incorrect output
5 Halted 0 ms 0 KB -