結果

問題 No.3599 Queen Moving Query
コンテスト
ユーザー kidodesu
提出日時 2026-07-24 21:53:27
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 2,074 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 248 ms
コンパイル使用メモリ 96,236 KB
実行使用メモリ 206,352 KB
最終ジャッジ日時 2026-07-24 21:56:02
合計ジャッジ時間 13,867 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def main():
    h, w, sy, sx = list(map(int, input().split()))
    sy, sx = sy-1, sx-1
    inf = 1<<60
    S = [input() for _ in range(h)]
    D = [[[inf]*8 for _ in range(w)] for _ in range(h)]
    D[sy][sx] = [1] * 8
    B = [(sy, sx, i) for i in range(8)]
    dy = [1, 1, 1, 0, -1, -1, -1, 0]
    dx = [1, 0, -1, -1, -1, 0, 1, 1]
    c = 1
    while A:= B:
        B = []
        while A:
            y, x, d = A.pop()
            if D[y][x][d] < c: continue
            for nd in range(8):
                ny, nx = y+dy[nd], x+dx[nd]
                if d == nd:
                    if 0 <= ny < h and 0 <= nx < w and c < D[ny][nx][nd] and S[ny][nx] == ".":
                        D[ny][nx][nd] = c
                        A.append((ny, nx, nd))
                else:
                    if 0 <= ny < h and 0 <= nx < w and c+1 < D[ny][nx][nd] and S[ny][nx] == ".":
                        D[ny][nx][nd] = c+1
                        B.append((ny, nx, nd))
        c += 1
    e = sum([1 for yx in range(h*w) if min(D[yx//w][yx%w]) != inf])
    f = 0
    if e == 3:
        X = []
        for y in range(h):
            for x in range(w):
                if min(D[y][x]) != inf and (sy, sx) != (y, x):
                    X.append((y, x))
        gy0, gx0 = X[0]
        gy1, gx1 = X[1]
        if gy0+gy1 == sy*2 and gx0+gx1 == sx*2:
            pass
        else:
            if abs(gy0-sy)+abs(gx0-sx) == 2 and abs(gy1-sy)+abs(gx1-sx) == 2:
                f = 1
    if not f and e != 2:
        for _ in range(int(input())):
            gy, gx, t = list(map(lambda x: int(x)-1, input().split()))
            t += 1
            ma = min(D[gy][gx])
            if ma <= t:
                print("Yes")
            else:
                print("No")
    else:
        for _ in range(int(input())):
            gy, gx, t = list(map(lambda x: int(x)-1, input().split()))
            t += 1
            if (sy, sx) == (gy, gx):
                print("Yes" if not t % 2 else "No")
            elif min(D[gy][gx]) != inf:
                print("Yes" if t % 2 else "No")

main()
0