結果
問題 | No.1851 Regular Tiling |
ユーザー |
|
提出日時 | 2022-02-26 01:23:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,503 bytes |
コンパイル時間 | 2,061 ms |
コンパイル使用メモリ | 173,464 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-03 20:37:12 |
合計ジャッジ時間 | 5,091 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | WA * 14 |
ソースコード
#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";}}}