結果
| 問題 |
No.1851 Regular Tiling
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-26 01:31:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 2,000 ms |
| コード長 | 1,543 bytes |
| コンパイル時間 | 1,762 ms |
| コンパイル使用メモリ | 174,120 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-03 20:47:01 |
| 合計ジャッジ時間 | 3,579 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
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++){
cout<<ans[i][0];
for(int j=1;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++){
cout<<ans[j][0];
for(int k=1;k<W;k++)cout<<' '<<ans[j][k];cout<<'\n';
}
flg=true;
break;
}
}
if(!flg)cout<<"-1\n";
}
}
}