제출 #1146975

#제출 시각아이디문제언어결과실행 시간메모리
1146975jahongirGardening (RMI21_gardening)C++20
0 / 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;


bool check(int i, int j, int a, int b, int k){
    if(i < 2 || j < 2){
        if(a*b==k) return true;
        return false;
    }
    int cnta = a*b-i*j;
    int cntb = (i-1)*(j-1)+1;

    if(cnta+cntb==k) return true;
    if(i==j && cnta + i == k) return true;
    return false;
}


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;

    int dx,dy;

    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            if(check(i,j,a,b,k)){
                dx = i;
                dy = j;
                goto cont;
            }
        }
    }
        
    cout << "NO\n";
    return;

    cont:;
    cout << "YES\n";
    int ans[n][m];
    memset(ans,0,sizeof ans);

    int cnt = 1;
    for(int i = 0; i < a; i++){
        for(int j = 0; j < b; j++){
            if(i < dx && j < dy) continue;
            ans[i*2][j*2] = cnt;
            ans[i*2][j*2+1] = cnt;
            ans[i*2+1][j*2] = cnt;
            ans[i*2+1][j*2+1] = cnt;
            cnt++;
        }
    }

    bool st = false;

    if(dx && dy){
        int cnta = a*b-dx*dy;
        if(dx==dy && cnta+dx==k) st = true;
    }

    if(st){
        for(int l = 0; l < dx; l++){
            for(int i = l; i < dx*2-l; i++){
                ans[i][l] = cnt;
                ans[l][i] = cnt;
                ans[i][dx*2-l-1] = cnt;
                ans[dx*2-l-1][i] = cnt;
            }
            cnt++;
        }
    }else{
        for(int i = 0; i < dx; i++){
            ans[i*2][0] = cnt;
            ans[i*2][dy*2-1] = cnt;
            ans[i*2+1][0] = cnt;
            ans[i*2+1][dy*2-1] = cnt;
        }
        for(int i = 0; i < dy; i++){
            ans[0][i*2] = cnt;
            ans[0][i*2+1] = cnt;
            ans[dx*2-1][i*2] = cnt;
            ans[dx*2-1][i*2+1] = cnt;
        }
        cnt++;
        for(int i = 0; i < dx-1; i++){
            for(int j = 0; j < dy-1; j++){
                ans[i*2+1][j*2+1] = cnt;
                ans[i*2+1][j*2+2] = cnt;
                ans[i*2+2][j*2+1] = cnt;
                ans[i*2+2][j*2+2] = cnt;
                cnt++;
            }
        }
    }
    cout << dx << ' ' << dy << '\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...