結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー auauaauaua
提出日時 2021-02-20 00:06:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 3,153 ms
コード長 2,520 bytes
コンパイル時間 1,745 ms
コンパイル使用メモリ 173,692 KB
実行使用メモリ 6,044 KB
最終ジャッジ日時 2023-10-17 02:00:40
合計ジャッジ時間 30,977 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 32 ms
6,044 KB
testcase_07 AC 5 ms
6,044 KB
testcase_08 AC 32 ms
6,044 KB
testcase_09 AC 32 ms
6,044 KB
testcase_10 AC 6 ms
6,044 KB
testcase_11 AC 32 ms
6,044 KB
testcase_12 AC 5 ms
6,044 KB
testcase_13 AC 33 ms
6,044 KB
testcase_14 AC 33 ms
6,044 KB
testcase_15 AC 6 ms
6,044 KB
testcase_16 AC 33 ms
6,044 KB
testcase_17 AC 33 ms
6,044 KB
testcase_18 AC 33 ms
6,044 KB
testcase_19 AC 33 ms
6,044 KB
testcase_20 AC 6 ms
6,044 KB
testcase_21 AC 33 ms
6,044 KB
testcase_22 AC 32 ms
6,044 KB
testcase_23 AC 6 ms
6,044 KB
testcase_24 AC 33 ms
6,044 KB
testcase_25 AC 5 ms
6,044 KB
testcase_26 AC 33 ms
6,044 KB
testcase_27 AC 32 ms
6,044 KB
testcase_28 AC 5 ms
6,044 KB
testcase_29 AC 33 ms
6,044 KB
testcase_30 AC 5 ms
6,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll inf=INF*INF;
const ll mod=1e9+7;
const ll MAX=140010;

int dx[]={-1,-1,-1,0,0,0,1,1,1};
int dy[]={-1,0,1,-1,0,1,-1,0,1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll w,h,x;cin>>w>>h>>x;
    vector<vector<ll> >ans(h+2,vector<ll>(w+2,-1));
    rep(i,h+2){
        ans[i][0]=0;
        ans[i][w+1]=0;
    }
    rep(i,w+2){
        ans[0][i]=0;
        ans[h+1][i]=0;
    }
    for(int i=h-2;i>=0;i--){
        for(int j=w;j>=0;j--){
            ans[i][j]=max(ans[i+3][j],ans[i][j]);
        }
    }
    for(int i=h;i>=0;i--){
        for(int j=w-2;j>=0;j--){
            ans[i][j]=max(ans[i][j+3],ans[i][j]);
        }
    }
    for(int i=3;i<h+1;i++){
        for(int j=0;j<w+1;j++){
            ans[i][j]=max(ans[i-3][j],ans[i][j]);
        }
    }
    for(int i=0;i<h+1;i++){
        for(int j=3;j<w+1;j++){
            ans[i][j]=max(ans[i][j-3],ans[i][j]);
        }
    }
    REP(i,1,h+1){
        REP(j,1,w+1){
            ll cnt=0;
            ll sum=0;
            rep(k,9){
                ll nx=i+dx[k];
                ll ny=j+dy[k];
                if(ans[nx][ny]==-1){
                    cnt++;
                }else{
                    sum+=ans[nx][ny];
                }
            }
            if(9LL*cnt>=x-sum){
                ll d=x-sum;
                sum=0;
                rep(k,9){
                    ll nx=i+dx[k];
                    ll ny=j+dy[k];
                    if(ans[nx][ny]==-1){
                        ll mi=min(d,9LL);
                        ans[nx][ny]=mi;
                        d-=mi;
                    }
                    sum+=ans[nx][ny];
                }
                if(sum!=x){
                    cout<<-1<<endl;
                    return 0;
                }
            }else{
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    REP(i,1,h+1){
        REP(j,1,w+1){
            cout<<ans[i][j];
        }
        cout<<endl;
    }
}
0