結果

問題 No.323 yuki国
ユーザー gew1fw
提出日時 2025-06-12 21:38:11
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,916 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 81,996 KB
実行使用メモリ 261,972 KB
最終ジャッジ日時 2025-06-12 21:42:52
合計ジャッジ時間 7,354 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 2 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    H = int(input[ptr])
    ptr += 1
    W = int(input[ptr])
    ptr += 1
    
    A = int(input[ptr])
    ptr += 1
    S_i = int(input[ptr])
    ptr += 1
    S_j = int(input[ptr])
    ptr += 1
    
    B = int(input[ptr])
    ptr += 1
    G_i = int(input[ptr])
    ptr += 1
    G_j = int(input[ptr])
    ptr += 1
    
    M = []
    for _ in range(H):
        M.append(input[ptr].strip())
        ptr += 1
    
    max_possible_size = 6000  # Based on problem constraints and movement possibilities
    visited = [[[False] * (max_possible_size + 2) for _ in range(W)] for _ in range(H)]
    
    queue = deque()
    initial_size = A
    if initial_size <= max_possible_size and initial_size > 0:
        queue.append((S_i, S_j, initial_size))
        visited[S_i][S_j][initial_size] = True
    
    directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    
    found = False
    while queue:
        i, j, size = queue.popleft()
        
        for di, dj in directions:
            ni = i + di
            nj = j + dj
            if 0 <= ni < H and 0 <= nj < W:
                cell = M[ni][nj]
                if cell == '*':
                    new_size = size + 1
                else:
                    new_size = size - 1
                
                if new_size <= 0:
                    continue
                if new_size > max_possible_size:
                    continue
                
                if not visited[ni][nj][new_size]:
                    visited[ni][nj][new_size] = True
                    queue.append((ni, nj, new_size))
                    
                    if ni == G_i and nj == G_j and new_size == B:
                        found = True
                        print("Yes")
                        return
    
    print("No")

if __name__ == "__main__":
    main()
0