結果

問題 No.1851 Regular Tiling
ユーザー Nzt3Nzt3
提出日時 2022-02-26 01:27:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,503 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 171,944 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-16 21:43:13
合計ジャッジ時間 4,546 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin>>T;
  while(T--){
    int H,W;
    cin>>H>>W;
    if(H>=3||W>=3){
      vector<vector<int>>ans(H,vector<int>(W));
      int tH=(H%3==1)*2,tW=(W%3==1)*2;
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if((i+tH)%3<2&&(j+tW)%3<2){
            ans[i][j]=2;
          }else if((i+tH)%3==2&&(j+tW)%3==2){
            ans[i][j]=0;
          }else{
            ans[i][j]=1;
          }
        }
      }
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          cout<<ans[i][j];
        }
        cout<<'\n';
      }
    }else{
      bool flg=false;
      for(int i=0;i<pow(3,H*W);i++){
        vector<vector<int>>ans(H,vector<int>(W));
        int t=i;
        for(int j=0;j<H*W;j++){
          ans[j/W][j%W]=t%3;
          t/=3;
        }
        bool ok=true;
        for(int j=0;j<H;j++){
          for(int k=0;k<W;k++){
            int cnt=0;
            if(j>0&&ans[j-1][k]==ans[j][k])cnt+=1;
            if(j<H-1&&ans[j+1][k]==ans[j][k])cnt+=1;
            if(k>0&&ans[j][k-1]==ans[j][k])cnt+=1;
            if(k<W-1&&ans[j][k+1]==ans[j][k])cnt+=1;
            if(ans[j][k]!=cnt)ok=false;
          }
        }
        if(ok){
          for(int j=0;j<H;j++){
            for(int k=0;k<W;k++)cout<<ans[j][k];cout<<'\n';
          }
          flg=true;
          break;
        }
      }
      if(!flg)cout<<"-1\n";
    }
  }
}
0