結果
問題 | No.86 TVザッピング(2) |
ユーザー |
![]() |
提出日時 | 2020-04-01 00:35:59 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,386 bytes |
コンパイル時間 | 88 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-06-25 14:47:45 |
合計ジャッジ時間 | 2,301 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 WA * 2 |
ソースコード
#!/usr/bin/ python3.8import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesH, 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 += 2W += 2dx = (1, -W, -1, W)S = A.index('.')def get_path(i, di):x = Spath = [x]se = set([x])while True:d = dx[i]if A[x + d] == '.':x += dif x in se:return pathpath.append(x)se.add(x)continuei = (i + di) % 4d = dx[i]if A[x + d] == '.':x += dif x in se:return pathpath.append(x)se.add(x)continuereturn pathpath1 = get_path(0, -1)path2 = []P = get_path(3, 1)[1:]n = sum(x == '.' for x in A)seP = set(path1)seQ = set()p = 0found = Falsewhile 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 += 1else:breakif path2 and path1[-1] == path2[-1] and len(path1) + len(path2) == n + 1:found = TruebreakseP.remove(path1.pop())print('YES' if found else 'NO')