結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー ShibuyapShibuyap
提出日時 2021-02-19 23:09:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,020 ms / 3,153 ms
コード長 4,280 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 208,368 KB
実行使用メモリ 5,488 KB
最終ジャッジ日時 2023-10-16 22:32:01
合計ジャッジ時間 36,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 111 ms
5,476 KB
testcase_07 AC 360 ms
5,476 KB
testcase_08 AC 32 ms
5,480 KB
testcase_09 AC 277 ms
5,480 KB
testcase_10 AC 241 ms
5,480 KB
testcase_11 AC 32 ms
5,480 KB
testcase_12 AC 8 ms
5,480 KB
testcase_13 AC 197 ms
5,480 KB
testcase_14 AC 3,020 ms
5,480 KB
testcase_15 AC 2,579 ms
5,480 KB
testcase_16 AC 29 ms
5,480 KB
testcase_17 AC 28 ms
5,480 KB
testcase_18 AC 29 ms
5,480 KB
testcase_19 AC 30 ms
5,480 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 29 ms
5,484 KB
testcase_22 AC 29 ms
5,484 KB
testcase_23 AC 5 ms
5,484 KB
testcase_24 AC 66 ms
5,480 KB
testcase_25 AC 30 ms
5,480 KB
testcase_26 AC 29 ms
5,484 KB
testcase_27 AC 29 ms
5,484 KB
testcase_28 AC 5 ms
5,484 KB
testcase_29 AC 29 ms
5,488 KB
testcase_30 AC 5 ms
5,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

int main() {
    int w, h, x;
    cin >> w >> h >> x;
    if(x > 36){
        cout << -1 << endl;
        return 0;
    }

    if(x == 0){
        rep(i,h){
            rep(j,w){
                cout << '0';
            }
            cout << endl;
        }
        return 0;
    }

    int f[h+100][w+100];
    rep(i,h+100){
        rep(j,w+100){
            f[i][j] = 0;
        }
    }

    rep(a,10){
        rep(b,10){
            rep(c,10){
                rep(d,10){
                    int hh = min(h,10);
                    int ww = min(w,10);
                    while(h%3!=hh%3) hh--;
                    while(w%3!=ww%3) ww--;
                    rep(i,hh){
                        rep(j,ww){
                            if(i%3==0&&j%3==0){
                                f[i][j] = a;
                            }
                            if(i%3==0&&j%3==1){
                                f[i][j] = b;
                            }
                            if(i%3==1&&j%3==0){
                                f[i][j] = c;
                            }
                            if(i%3==1&&j%3==1){
                                f[i][j] = d;
                            }
                        }
                    }
                    int ok = 1;
                    rep(i,hh){
                        rep(j,ww){
                            if(hh>=10&&i==hh-1) continue;
                            if(ww>=10&&j==ww-1) continue;
                            int sum = 0;
                            srep(k,-1,2){
                                srep(l,-1,2){
                                    if(i+k>=0&&j+l>=0){
                                        sum += f[i+k][j+l];
                                    }
                                }
                            }
                            if(sum != x){
                                ok = 0;
                                break;
                            }
                        }
                        if(ok == 0) break;
                    }
                    if(ok){
                        rep(i,h){
                            rep(j,w){
                                if(i%3==0&&j%3==0){
                                    f[i][j] = a;
                                }
                                if(i%3==0&&j%3==1){
                                    f[i][j] = b;
                                }
                                if(i%3==1&&j%3==0){
                                    f[i][j] = c;
                                }
                                if(i%3==1&&j%3==1){
                                    f[i][j] = d;
                                }
                            }
                        }
                        
                        rep(i,h){
                            rep(j,w){
                                int sum = 0;
                                srep(k,-1,2){
                                    srep(l,-1,2){
                                        if(i+k>=0&&j+l>=0){
                                            sum += f[i+k][j+l];
                                        }
                                    }
                                }
                                if(sum != x){
                                    ok = 0;
                                    break;
                                }
                            }
                            if(ok == 0) break;
                        }
                        if(ok){
                            rep(i,h){
                                rep(j,w){
                                    cout << f[i][j];
                                }
                                cout << endl;
                            }
                            return 0;
                        }
                        
                    }
                }
            }
        }
    }
    
    cout << -1 << endl;
    return 0;
}
 
 
0