結果
問題 | No.20 砂漠のオアシス |
ユーザー | rpy3cpp |
提出日時 | 2015-08-08 10:49:29 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,250 bytes |
コンパイル時間 | 351 ms |
コンパイル使用メモリ | 11,032 KB |
実行使用メモリ | 10,724 KB |
最終ジャッジ日時 | 2023-08-03 07:47:04 |
合計ジャッジ時間 | 2,311 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
8,176 KB |
testcase_01 | AC | 18 ms
8,188 KB |
testcase_02 | AC | 18 ms
8,156 KB |
testcase_03 | AC | 22 ms
8,224 KB |
testcase_04 | AC | 22 ms
8,040 KB |
testcase_05 | AC | 117 ms
10,264 KB |
testcase_06 | AC | 36 ms
9,408 KB |
testcase_07 | AC | 131 ms
10,724 KB |
testcase_08 | AC | 51 ms
9,396 KB |
testcase_09 | AC | 114 ms
10,464 KB |
testcase_10 | AC | 18 ms
8,224 KB |
testcase_11 | WA | - |
testcase_12 | AC | 22 ms
8,192 KB |
testcase_13 | AC | 21 ms
8,132 KB |
testcase_14 | AC | 28 ms
8,112 KB |
testcase_15 | AC | 25 ms
8,128 KB |
testcase_16 | AC | 42 ms
8,612 KB |
testcase_17 | AC | 34 ms
8,192 KB |
testcase_18 | AC | 36 ms
8,624 KB |
testcase_19 | AC | 40 ms
8,652 KB |
testcase_20 | AC | 20 ms
8,112 KB |
ソースコード
import heapq def read_data(): N, V, Ox, Oy = map(int, input().split()) data = [list(map(int, input().split())) for n in range(N)] return N, V, Ox - 1, Oy - 1, data def solve(N, V, Ox, Oy, data): Sx, Sy = 0, 0 Gx, Gy = N - 1, N - 1 distS = dijkstra(Sx, Sy, data, N, V) if distS[Gx][Gy] < V: return True if Ox == -1 and Oy == -1: return False newV = (V - distS[Ox][Oy]) * 2 if newV <= 0: return False distO = dijkstra(Ox, Oy, data, N, newV) if distO[Gx][Gy] < newV: return True return False def dijkstra(x, y, data, N, V): pq = [(0, x, y)] dist = [[float('inf')] * N for n in range(N)] dist[0][0] = 0 while pq: d, x, y = heapq.heappop(pq) for nx, ny in [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]: if nx < 0 or nx >= N or ny < 0 or ny >= N: continue newd = d + data[ny][nx] if newd >= V or newd >= dist[nx][ny]: continue dist[nx][ny] = newd heapq.heappush(pq, (newd, nx, ny)) return dist if __name__ == '__main__': N, V, Ox, Oy, data = read_data() if solve(N, V, Ox, Oy, data): print('YES') else: print('NO')