제출 #1146930

#제출 시각아이디문제언어결과실행 시간메모리
1146930jahongirGardening (RMI21_gardening)C++20
11 / 100
37 ms832 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
 
using namespace std;
using namespace __gnu_pbds;
using pi = pair<int,int>;
using vi = vector<int>;
#define f first
#define s second
#define pb push_back
#define ll long long
#define all(v)  (v).begin(),(v).end()
 
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
 
void setIO(string name = ""){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    if(name.empty()){
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }else{
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}


const int mxn = 210;


void solve2(vector<vector<int>> &ans, int cnt, int k, int a, int b, int sx, int sy){
    if(k==0) return;
    if(k <= (a-1)*(b-1)+1){
        for(int i = sy; i < sy+2*b; i++){
            ans[sx][i] = cnt;
            ans[sx+2*a-1][i] = cnt;
        }
        for(int i = sx; i < sx+2*a; i++){
            ans[i][sy] = cnt;
            ans[i][sy+2*b-1] = cnt;
        }
        solve2(ans,cnt+1,k-1,a-1,b-1,sx+1,sy+1);
        return;
    }
    if(k==a*b){
        for(int i = sx; i < sx+2*a; i+=2){
            for(int j = sy; j < sy+2*b; j+=2){
                ans[i][j] = ans[i][j+1] = cnt;
                ans[i+1][j] = ans[i+1][j+1] = cnt;
                cnt++;
            }
        }
        return;
    }
    if((a-1)*b < k){
        int needed = a*b-k;
        for(int i = sy; i < sy+2*needed; i++){
            ans[sx][i] = ans[sx+3][i] = cnt; 
        }
        ans[sx+1][sy] = ans[sx+2][sy] = cnt;
        ans[sx+1][sy+2*needed-1] = ans[sx+2][sy+2*needed-1] = cnt;
        cnt++;
        for(int i = sy+1; i < 2*needed-1; i+=2){
            ans[sx+1][i] = ans[sx+1][i+1] = cnt;
            ans[sx+2][i] = ans[sx+2][i+1] = cnt;
            cnt++;
        }
        for(int i = sx; i < sx+4; i+=2){
            for(int j = sy+2*needed; j < sy+2*b; j+=2){
                ans[i][j] = ans[i][j+1] = cnt;
                ans[i+1][j] = ans[i+1][j+1] = cnt;
                cnt++;
            }
        }
        for(int i = sx+4; i < sx+2*a; i+=2){
            for(int j = sy; j < sy+2*b; j+=2){
                ans[i][j] = ans[i][j+1] = cnt;
                ans[i+1][j] = ans[i+1][j+1] = cnt;
                cnt++;
            }
        }
        return;
    }

    int x = k + a + b - a*b;

    for(int i = sx; i < sx+2*x; i+=2){
        for(int j = sy; j < sy+2*b; j+=2){
            ans[i][j] = ans[i][j+1] = cnt;
            ans[i+1][j] = ans[i+1][j+1] = cnt;
            cnt++;
        }
    }

    solve2(ans,cnt,k-b*x,a-x,b,sx+2*x,sy);

}


void solve(){
    
    int n,m,k;
    cin >> n >> m >> k;

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

    int a = n/2, b = m/2;

    if((a%3==0 && a==b && k == a+1) ||
        (k < max(a,b)) || (k > a*b) || (k==a*b-1)){
        cout << "NO\n";
        return;
    }

    vector<vector<int>> ans(n,vector<int>(m,0));

    solve2(ans,1,k,a,b,0,0);
    cout << "YES\n";
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cout << ans[i][j] << ' ';
        cout << '\n';
    }
}
 
signed main(){
    // setIO();
    int t = 1;
    cin >> t;    
    while(t--) solve();
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...