結果

問題 No.1851 Regular Tiling
ユーザー titia
提出日時 2022-02-25 21:41:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 85,632 KB
最終ジャッジ日時 2024-07-03 16:26:27
合計ジャッジ時間 4,221 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

ANS=[]

for i in range(120):
    if i%3==0:
        A=[1,1,0]*40
        ANS.append(A)
    else:
        A=[2,2,1]*40
        ANS.append(A)
        

def check(X):
    for i in range(len(X)):
        for j in range(len(X[0])):
            x=X[i][j]
            count=0

            for z,w in [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]:
                if 0<=z<len(X) and 0<=w<len(X[0]) and X[z][w]==x:
                    count+=1

            if count!=x:
                return False
    return True


T=int(input())
for tests in range(T):
    H,W=map(int,input().split())

    L=[]

    for i in range(H):
        L.append(ANS[i][:W])

    if check(L)==True:
        for l in L:
            print(*l)
        continue

    L=[]

    for i in range(H):
        L.append(ANS[i+1][:W])

    if check(L)==True:
        for l in L:
            print(*l)
        continue

    L=[]

    for i in range(H):
        L.append(ANS[i][2:W+2])

    if check(L)==True:
        for l in L:
            print(*l)
        continue

    L=[]

    for i in range(H):
        L.append(ANS[i+1][2:W+2])

    if check(L)==True:
        for l in L:
            print(*l)
        continue

    print(-1)

    
        
        
        

    
0