結果

問題 No.323 yuki国
ユーザー Leonardone
提出日時 2015-12-16 23:46:34
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 2,440 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 7,168 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-16 06:09:31
合計ジャッジ時間 1,805 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 24 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU

def gis():
    return map(int, raw_input().split())
def arr2d(h,w):
    return [[0] * w for _ in xrange(h)]


def solve():
    ansYes = "Yes"
    ansNo = "No"
    pCh = "*"
    mCh = "."
    
    (h,w) = gis() 
    (a, si, sj) = start = gis()
    (b, gi, gj) = goal = gis()
    m = [raw_input() for _ in xrange(h)]
    
    l = abs(si - gi) + abs(sj - gj)
    if l % 2 == 0 and a % 2 != b % 2:
        print ansNo
        return
    if l % 2 == 1 and a % 2 == b % 2:
        print ansNo
        return
    
    minus = arr2d(h,w)
    plus = arr2d(h,w)
    
    def chk(rch2, c, y2, x2):
        if m[y2][x2] == pCh:
            if plus[y2][x2] == 0:
                rch2.append([c + 1, y2, x2])
                plus[y2][x2] = 1
        elif c > 1 and minus[y2][x2] < c - 1:
            rch2.append([c - 1, y2, x2])
            minus[y2][x2] = c - 1
    
    rch1 = [start]
    while len(rch1) > 0:
        rch2 = []
        for (c,y,x) in rch1:
            if x > 0:
                chk(rch2, c, y, x - 1) 
            if y > 0:
                chk(rch2, c, y - 1, x)
            if x + 1 < w:
                chk(rch2, c, y, x + 1)
            if y + 1 < h:
                chk(rch2, c, y + 1, x)
        rch1 = rch2
    
    mcount = 0
    for ml in m:
        mcount += ml.count(mCh)
    if mcount < 2 and a + l > b:
        print ansYes
        return
    
    gplus = False
    if m[gi][gj] == pCh:
        if gi > 0 and m[gi - 1][gj] == pCh:
            gplus = True
        if gj > 0 and m[gi][gj - 1] == pCh:
            gplus = True
        if gi + 1 < h and m[gi + 1][gj] == pCh:
            gplus = True
        if gj + 1 < w and m[gi][gj + 1] == pCh:
            gplus =True
    if gplus:
        print ansYes
        return
    
    if plus[gi][gj] > 0:
        print ansYes
        return
    
    flagP = False
    
    for i in xrange(h):
        for j in xrange(1,w):
            if plus[i][j] > 0 and plus[i][j - 1] > 0:
                flagP = True
                
    for j in xrange(w):
        for i in xrange(1,h):
            if plus[i][j] > 0 and plus[i - 1][j] > 0:
                flagP = True
    
    if flagP:
        if m[gi][gj] == pCh and gplus == False:
            print ansNo
            return
        print ansYes
        return
    
    if minus[gi][gj] > 0:
        print ansYes
        return
    
    print ansNo


solve()
0