結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー umezo
提出日時 2021-02-19 23:16:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 28 ms / 3,153 ms
コード長 2,363 bytes
コンパイル時間 2,752 ms
コンパイル使用メモリ 194,552 KB
最終ジャッジ日時 2025-01-19 01:43:29
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  int w,h,x;
  cin>>w>>h>>x;

  if(x>36) cout<<-1<<endl;
  else if(x<=9){
    if(w%3==1 && h%3==1){
      rep(i,h){
        rep(j,w){
          if(i%3==0 && j%3==0) cout<<x;
          else cout<<0;
        }
        cout<<endl;
      }
    }
    else if(w%3==1){
      rep(i,h){
        rep(j,w){
          if(i%3==1 && j%3==0) cout<<x;
          else cout<<0;
        }
        cout<<endl;
      }
    }
    else if(h%3==1){
      rep(i,h){
        rep(j,w){
          if(i%3==0 && j%3==1) cout<<x;
          else cout<<0;
        }
        cout<<endl;
      }
    }
    else{
      rep(i,h){
        rep(j,w){
          if(i%3==1 && j%3==1) cout<<x;
          else cout<<0;
        }
        cout<<endl;
      }
    }
  }
  else{
    if(h%3==2 && w%3==2){
      int a,b,c,d;
      if(x<=18) a=9,b=x-9,c=0,d=0;
      else if(x<=27) a=9,b=9,c=x-18,d=0;
      else a=9,b=9,c=9,d=x-27;
      rep(i,h){
        rep(j,w){
          if(i%3==0 && j%3==0) cout<<a;
          else if(i%3==1 && j%3==0) cout<<b;
          else if(i%3==0 && j%3==1) cout<<c;
          else if(i%3==1 && j%3==1) cout<<d;
          else cout<<0;
        }
        cout<<endl;
      }
    }
    else if(h%3==2 && w%3==1 && x<=18){
      int a=9,b=x-9;
       rep(i,h){
        rep(j,w){
          if(i%3==0 && j%3==0) cout<<a;
          else if(i%3==1 && j%3==0) cout<<b;
          else cout<<0;
        }
        cout<<endl;
      }
    }
    else if(h%3==1 && w%3==2 && x<=18){
      int a=9,b=x-9;
       rep(i,h){
        rep(j,w){
          if(i%3==0 && j%3==0) cout<<a;
          else if(i%3==0 && j%3==1) cout<<b;
          else cout<<0;
        }
        cout<<endl;
      }
    }
    else if(h%3==2 && w%3==0 && x<=18){
      int a=9,b=x-9;
       rep(i,h){
        rep(j,w){
          if(i%3==0 && j%3==1) cout<<a;
          else if(i%3==1 && j%3==1) cout<<b;
          else cout<<0;
        }
        cout<<endl;
      }
    }
    else if(h%3==0 && w%3==2 && x<=18){
      int a=9,b=x-9;
       rep(i,h){
        rep(j,w){
          if(i%3==1 && j%3==0) cout<<a;
          else if(i%3==1 && j%3==1) cout<<b;
          else cout<<0;
        }
        cout<<endl;
      }
    }
    else cout<<-1<<endl;
  }
  

  return 0;
}
0