結果
問題 | No.1398 調和の魔法陣 (構築) |
ユーザー | auaua |
提出日時 | 2021-02-20 00:06:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 3,153 ms |
コード長 | 2,520 bytes |
コンパイル時間 | 3,861 ms |
コンパイル使用メモリ | 173,992 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 00:34:49 |
合計ジャッジ時間 | 29,334 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#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; } }