結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー snow39snow39
提出日時 2021-02-19 22:15:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 3,153 ms
コード長 1,800 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 96,448 KB
実行使用メモリ 4,420 KB
最終ジャッジ日時 2023-10-15 02:20:30
合計ジャッジ時間 25,118 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int W,H,X;
  cin>>W>>H>>X;

  for(int a=0;a<=9;a++) for(int b=0;b<=9;b++) for(int c=0;c<=9;c++) for(int d=0;d<=9;d++){
    if(a+b+c+d!=X) continue;

    int R=min(H,6+H%3);
    int C=min(W,6+W%3);
    vector<vector<int>> A(R,vector<int> (C,0));
    for(int i=0;i<R;i++) for(int j=0;j<C;j++){
      A[i][j]=0;
      if(i%3==0){
        if(j%3==0) A[i][j]=a;
        if(j%3==1) A[i][j]=b;
      }else if(i%3==1){
        if(j%3==0) A[i][j]=c;
        if(j%3==1) A[i][j]=d;
      }
    }

    bool ng=false;
    for(int i=0;i<R;i++) for(int j=0;j<C;j++){
      int res=0;
      for(int k=-1;k<=1;k++) for(int l=-1;l<=1;l++){
        int nx=i+k;
        int ny=j+l;
        if(nx<0||ny<0||nx>=R||ny>=C) continue;
        res+=A[nx][ny];
      }
      if(res!=X){
        ng=true;
        break;
      }
    }

    if(ng) continue;

    vector<vector<int>> ans(H,vector<int> (W,0));
    for(int i=0;i<H;i++) for(int j=0;j<W;j++){
      if(i%3==0){
        if(j%3==0) ans[i][j]=a;
        if(j%3==1) ans[i][j]=b;
      }else if(i%3==1){
        if(j%3==0) ans[i][j]=c;
        if(j%3==1) ans[i][j]=d;
      }
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++) cout<<ans[i][j];
      cout<<"\n";
    }
    return 0;
  }

  cout<<-1<<"\n";

  return 0;
}
0