結果

問題 No.86 TVザッピング(2)
ユーザー maspymaspy
提出日時 2020-04-01 00:37:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,433 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 11,116 KB
実行使用メモリ 8,496 KB
最終ジャッジ日時 2023-09-07 21:11:16
合計ジャッジ時間 2,555 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,068 KB
testcase_01 AC 16 ms
8,068 KB
testcase_02 AC 16 ms
8,060 KB
testcase_03 AC 17 ms
8,104 KB
testcase_04 AC 17 ms
8,100 KB
testcase_05 AC 16 ms
8,100 KB
testcase_06 AC 16 ms
8,064 KB
testcase_07 AC 16 ms
8,156 KB
testcase_08 AC 18 ms
8,480 KB
testcase_09 AC 18 ms
8,356 KB
testcase_10 AC 18 ms
8,388 KB
testcase_11 AC 17 ms
8,016 KB
testcase_12 AC 17 ms
8,268 KB
testcase_13 AC 17 ms
8,068 KB
testcase_14 AC 18 ms
8,376 KB
testcase_15 AC 18 ms
8,352 KB
testcase_16 AC 18 ms
8,376 KB
testcase_17 AC 17 ms
8,108 KB
testcase_18 AC 17 ms
8,172 KB
testcase_19 AC 17 ms
8,096 KB
testcase_20 AC 17 ms
8,176 KB
testcase_21 AC 18 ms
8,376 KB
testcase_22 AC 17 ms
8,104 KB
testcase_23 AC 18 ms
8,496 KB
testcase_24 AC 17 ms
8,068 KB
testcase_25 AC 16 ms
8,300 KB
testcase_26 WA -
testcase_27 AC 16 ms
8,096 KB
testcase_28 AC 16 ms
8,068 KB
testcase_29 AC 17 ms
8,344 KB
testcase_30 AC 16 ms
8,036 KB
testcase_31 AC 16 ms
8,104 KB
testcase_32 AC 16 ms
8,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, readline().split())
A = ['#' * (W + 2)]
for _ in range(H):
    A.append('#' + readline().decode().rstrip() + '#')
A += ['#' * (W + 2)]
A = tuple(''.join(A))

H += 2
W += 2
dx = (1, -W, -1, W)
S = A.index('.')
if A[S + W] == '#':
    print('NO')
    exit()


def get_path(i, di):
    x = S
    path = [x]
    se = set([x])
    while True:
        d = dx[i]
        if A[x + d] == '.':
            x += d
            if x in se:
                return path
            path.append(x)
            se.add(x)
            continue
        i = (i + di) % 4
        d = dx[i]
        if A[x + d] == '.':
            x += d
            if x in se:
                return path
            path.append(x)
            se.add(x)
            continue
        return path


path1 = get_path(0, -1)
path2 = []
P = get_path(3, 1)[1:]
n = sum(x == '.' for x in A)

seP = set(path1)
seQ = set()
p = 0

found = False
while path1:
    while True:
        if p < len(P) and ((P[p] not in seP) or (P[p] == path1[-1])):
            seQ.add(P[p])
            path2.append(P[p])
            p += 1
        else:
            break
    if path2 and path1[-1] == path2[-1] and len(path1) + len(path2) == n + 1:
        found = True
        break
    seP.remove(path1.pop())

print('YES' if found else 'NO')
0