Submission #770762

# Submission time Handle Problem Language Result Execution time Memory
770762 2023-07-01T22:02:08 Z gg123_pe Gardening (RMI21_gardening) C++14
0 / 100
26 ms 948 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; 
        }
        cout << "YES\n"; 
        vector <vector<int>> v(n, vector <int> (m)); 
        
        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; 
            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++; 
            }
        }
        print(v); 
    }
    return 0; 
}
# Verdict Execution time Memory Grader output
1 Failed 26 ms 948 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 26 ms 948 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 26 ms 948 KB Incorrect output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 1 ms 320 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 Failed 26 ms 948 KB Incorrect output
2 Halted 0 ms 0 KB -