結果

問題 No.86 TVザッピング(2)
ユーザー ytftytft
提出日時 2022-11-09 22:32:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,167 ms / 5,000 ms
コード長 796 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 30,212 KB
最終ジャッジ日時 2023-09-30 09:27:48
合計ジャッジ時間 11,382 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
29,740 KB
testcase_01 AC 139 ms
29,804 KB
testcase_02 AC 134 ms
29,780 KB
testcase_03 AC 135 ms
29,740 KB
testcase_04 AC 136 ms
29,740 KB
testcase_05 AC 137 ms
29,908 KB
testcase_06 AC 137 ms
29,752 KB
testcase_07 AC 134 ms
29,748 KB
testcase_08 AC 1,167 ms
29,988 KB
testcase_09 AC 143 ms
29,668 KB
testcase_10 AC 144 ms
29,764 KB
testcase_11 AC 149 ms
29,868 KB
testcase_12 AC 137 ms
29,796 KB
testcase_13 AC 141 ms
29,920 KB
testcase_14 AC 590 ms
30,212 KB
testcase_15 AC 425 ms
29,896 KB
testcase_16 AC 582 ms
30,040 KB
testcase_17 AC 145 ms
29,720 KB
testcase_18 AC 155 ms
29,744 KB
testcase_19 AC 144 ms
29,812 KB
testcase_20 AC 140 ms
29,776 KB
testcase_21 AC 142 ms
29,892 KB
testcase_22 AC 139 ms
29,800 KB
testcase_23 AC 730 ms
29,892 KB
testcase_24 AC 141 ms
29,800 KB
testcase_25 AC 137 ms
29,944 KB
testcase_26 AC 138 ms
29,696 KB
testcase_27 AC 137 ms
29,756 KB
testcase_28 AC 138 ms
29,800 KB
testcase_29 AC 146 ms
29,956 KB
testcase_30 AC 136 ms
29,764 KB
testcase_31 AC 139 ms
29,740 KB
testcase_32 AC 139 ms
29,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,copy
import numpy as np
input=lambda:sys.stdin.readline().rstrip()
turn=np.array([[0,1],[-1,0]])
def search(B,pos,d,cnt):
	A=copy.copy(B)
	orig=[pos[0],pos[1]]
	while 1:
		for i in range(2):
			if A[(pos+d)[0]][(pos+d)[1]]==0:
				pos+=d
				A[pos[0]][pos[1]]=1
				cnt-=1
				break
			d=d@turn
		else:
			return cnt==0 and pos[0]==orig[0] and pos[1]==orig[1]
H,W=map(int,input().split())
A=np.array([[1 for j in range(W+2)] for i in range(H+2)])
ans,cnt=0,0
for i in range(H):
	S=input()
	for j in range(W):
		A[i+1][j+1]=(S[j]=='#')
		cnt+=(S[j]=='.')
if cnt>2*(H+W):
	print('NO')
	sys.exit()
for i in range(H):
	for j in range(W):
		if A[i+1][j+1]:
			continue
		d=np.array([1,0])
		for k in range(4):
			ans|=search(A,np.array([i+1,j+1]),d,cnt)
			d=d@turn
print(['NO','YES'][ans])
0