結果

問題 No.323 yuki国
ユーザー nebukuro09nebukuro09
提出日時 2016-09-23 13:56:24
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 1,600 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 77,056 KB
実行使用メモリ 78,464 KB
最終ジャッジ日時 2024-04-28 21:28:17
合計ジャッジ時間 4,945 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
75,264 KB
testcase_01 AC 96 ms
75,648 KB
testcase_02 AC 95 ms
75,648 KB
testcase_03 AC 95 ms
75,776 KB
testcase_04 AC 91 ms
75,392 KB
testcase_05 AC 96 ms
75,264 KB
testcase_06 AC 95 ms
75,520 KB
testcase_07 AC 86 ms
75,776 KB
testcase_08 AC 86 ms
75,392 KB
testcase_09 AC 87 ms
75,520 KB
testcase_10 WA -
testcase_11 AC 87 ms
75,648 KB
testcase_12 AC 87 ms
75,264 KB
testcase_13 AC 87 ms
75,648 KB
testcase_14 AC 87 ms
75,776 KB
testcase_15 AC 98 ms
78,208 KB
testcase_16 AC 86 ms
75,392 KB
testcase_17 AC 88 ms
75,264 KB
testcase_18 AC 89 ms
75,392 KB
testcase_19 AC 87 ms
75,264 KB
testcase_20 AC 87 ms
75,776 KB
testcase_21 AC 86 ms
75,648 KB
testcase_22 AC 88 ms
75,520 KB
testcase_23 AC 90 ms
75,904 KB
testcase_24 AC 101 ms
77,568 KB
testcase_25 AC 90 ms
75,264 KB
testcase_26 AC 107 ms
78,464 KB
testcase_27 AC 87 ms
75,392 KB
testcase_28 AC 89 ms
75,392 KB
testcase_29 AC 89 ms
75,392 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 89 ms
75,520 KB
testcase_36 WA -
testcase_37 AC 88 ms
75,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, raw_input().split())
A, Sr, Sc = map(int, raw_input().split())
B, Gr, Gc = map(int, raw_input().split())

if (abs(Sr-Gr)+abs(Sc-Gc))%2 != abs(A-B)%2:
    print 'No'
    exit()

board = [raw_input() for _ in xrange(H)]
dr = [0, 0, 1, -1]
dc = [1, -1, 0, 0]

if board[Gr][Gc] == '*' and B == 1:
    for i in xrange(4):
        nr, nc = Gr+dr[i], Gc+dc[i]
        if 0 <= nr < H and 0 <= nc < W and board[nr][nc] == '*':
            break
    else:
        print 'No'
        exit()

if abs(A-B) >= abs(Sr-Gr)+abs(Sc-Gc):
    print 'Yes'
    exit()

goals = set()
for i in xrange(H):
    for j in xrange(W):
        if (i, j) in goals:
            continue
        if board[i][j] == '.':
            continue
        for k in xrange(4):
            nr, nc = i+dr[k], j+dr[k]
            if 0 <= nr < H and 0 <= nc < W and board[nr][nc] == '*':
                goals.add((i, j))
                goals.add((nr, nc))

reachable = {}
stack = [((Sr, Sc), A)]
while len(stack) > 0:
    node, size = stack.pop()
    if node in goals and size >= 1:
        print 'Yes'
        exit()
    if node in reachable and reachable[node] >= size:
        continue
    reachable[node] = size
    for i in xrange(4):
        nr, nc = node[0]+dr[i], node[1]+dc[i]
        if nr < 0 or nr >= H or nc < 0 or nc >= W:
            continue
        new_size = size + 1 if board[nr][nc] == '*' else size - 1
        if new_size <= 0:
            continue
        if (nr, nc) in reachable and reachable[(nr, nc)] >= new_size:
            continue
        stack.append(((nr, nc), new_size))
print 'No'
            
0