結果

問題 No.20 砂漠のオアシス
ユーザー dangodango
提出日時 2023-07-08 18:26:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,834 ms / 5,000 ms
コード長 785 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 264,204 KB
最終ジャッジ日時 2023-09-29 19:46:06
合計ジャッジ時間 16,998 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,076 KB
testcase_01 AC 71 ms
71,304 KB
testcase_02 AC 83 ms
76,396 KB
testcase_03 AC 135 ms
80,412 KB
testcase_04 AC 206 ms
82,904 KB
testcase_05 AC 270 ms
115,148 KB
testcase_06 AC 281 ms
82,372 KB
testcase_07 AC 4,834 ms
264,204 KB
testcase_08 AC 941 ms
101,948 KB
testcase_09 AC 2,988 ms
162,560 KB
testcase_10 AC 72 ms
71,204 KB
testcase_11 AC 73 ms
70,964 KB
testcase_12 AC 248 ms
83,080 KB
testcase_13 AC 246 ms
82,960 KB
testcase_14 AC 565 ms
87,860 KB
testcase_15 AC 383 ms
85,536 KB
testcase_16 AC 1,031 ms
99,728 KB
testcase_17 AC 507 ms
83,732 KB
testcase_18 AC 841 ms
95,772 KB
testcase_19 AC 989 ms
99,808 KB
testcase_20 AC 171 ms
79,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, V, Ox, Oy = map(int, input().split())
Ox -= 1
Oy -= 1
L = [list(map(int, input().split())) for _ in range(N)]
visited = [[0] * N for _ in range(N)]

def dfs(x, y, v):
    visited[y][x] = v
    if x == N - 1 and y == N - 1:
        return 1
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    for d in range(4):
        nx = x + dx[d]
        ny = y + dy[d]
        if nx >= 0 and nx < N and ny >= 0 and ny < N:
            r = v - L[ny][nx]
            if r > visited[ny][nx]:
                if dfs(nx, ny, r):
                    return 1
    return 0

possible = dfs(0, 0, V)
if not possible:
    r = visited[Oy][Ox]
    if not (Ox == 0 and Oy == 0) and r > 0:
        visited = [[0] * N for _ in range(N)]
        possible = dfs(Ox, Oy, r * 2)

print("YES" if possible else "NO")
0