結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー fumofumofunifumofumofuni
提出日時 2021-02-19 22:42:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,109 bytes
コンパイル時間 2,952 ms
コンパイル使用メモリ 210,428 KB
実行使用メモリ 6,216 KB
最終ジャッジ日時 2023-10-15 03:39:39
合計ジャッジ時間 26,728 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,352 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,352 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 27 ms
5,992 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 27 ms
5,932 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,348 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 26 ms
5,880 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 27 ms
6,024 KB
testcase_30 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
    return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
    return ((a > b) ? (a = b, true) : (false));
}
ll h,w,x;
vvl ans;
void dfs(vvl &g){
    rep(i,h){
        rep(j,w){
            if(g[i][j]==-1){
                for(int k=0;k<=9;k++){
                    g[i][j]=k;
                    g[i][w-j-1]=k;
                    g[h-i-1][j]=k;
                    g[h-i-1][w-j-1]=k;
                    dfs(g);
                }
                g[i][j]=-1;
                g[i][w-j-1]=-1;
                g[h-i-1][j]=-1;
                g[h-i-1][w-j-1]=-1;
                return;
            }
        }
    }
    bool ok=true;
    rep(i,h){
        rep(j,w){
            ll p=g[i][j];
            rep(k,8){
                ll nx=i+dx[k],ny=j+dy[k];
                if(nx<0||ny<0||nx>=h||ny>=w)continue;
                p+=g[nx][ny];
            }
            if(p!=x)ok=false;
        }
    }
    if(ok)ans=g;
    return ;
}

void dfs2(vvl &g){
    rep(i,h){
        rep(j,w){
            if(g[i][j]==-1){
                for(int k=0;k<=9;k++){
                    g[i][j]=k;
                    dfs2(g);
                }
                g[i][j]=-1;
                return;
            }
        }
    }
    bool ok=true;
    rep(i,h){
        rep(j,w){
            ll p=g[i][j];
            rep(k,8){
                ll nx=i+dx[k],ny=j+dy[k];
                if(nx<0||ny<0||nx>=h||ny>=w)continue;
                p+=g[nx][ny];
            }
            if(p!=x)ok=false;
        }
    }
    if(ok)ans=g;
    return;
}

int main(){
    cin >> w >>h >> x;
    if(x==0){
        rep(i,h){
            rep(j,w)cout << 0;
            cout << endl;
        }
        return 0;
    }
    if(h>=6||w>=6){
        if(x>=10)cout << -1 <<endl,exit(0);
        vvl g(h,vl(w));
        rep(i,h){
            rep(j,w){
                if(j%3==1&&i%3==1){
                    g[i][j]=x;
                }
            }
        }
        bool ok=true;
        rep(i,h){
            rep(j,w){
                ll p=g[i][j];
                rep(k,8){
                    ll nx=i+dx[k],ny=j+dy[k];
                    if(nx<0||ny<0||nx>=h||ny>=w)continue;
                    p+=g[nx][ny];
                }
                if(p!=x)ok=false;
            }
        }
        if(ok){
            rep(i,h){
                rep(j,w)cout << g[i][j];cout << endl;
            }
        }
        else cout << -1 <<endl;
        return 0;
    }
    vvl g(h,vl(w,-1));
    for(auto x:vector<ll>{0,h-1}){
        for(auto y:vector<ll>{0,w-1}){
            for(int i=-2;i<=2;i++){
                for(int j=-2;j<=2;j++){
                    if(abs(i)==2||abs(j)==2){
                        if(x+i<0||x+i>=h||y+j<0||y+j>=w)continue;
                        g[x+i][y+j]=0;
                    }
                }
            }
        }
    }
    if(h<=2&&w<=2){
        dfs2(g);
        if(ans.size()==h){
            rep(i,h){
                rep(j,w)cout << ans[i][j];
                cout << endl;
            }
        }
        else cout << -1 <<endl;
        return 0;
    }
    dfs(g);
    if(ans.size()==h){
        rep(i,h){
            rep(j,w){
                cout << ans[i][j];
            }
            cout << endl;
        } 
    }
    else cout << -1 <<endl;
}   
0