結果
問題 | No.20 砂漠のオアシス |
ユーザー | szkhts |
提出日時 | 2021-04-22 11:02:36 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
WA
|
実行時間 | - |
コード長 | 943 bytes |
コンパイル時間 | 120 ms |
コンパイル使用メモリ | 10,816 KB |
実行使用メモリ | 11,208 KB |
最終ジャッジ日時 | 2023-09-17 09:56:00 |
合計ジャッジ時間 | 2,205 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
8,248 KB |
testcase_01 | AC | 17 ms
8,004 KB |
testcase_02 | AC | 17 ms
8,116 KB |
testcase_03 | AC | 21 ms
8,396 KB |
testcase_04 | AC | 24 ms
8,096 KB |
testcase_05 | AC | 146 ms
10,296 KB |
testcase_06 | AC | 157 ms
11,128 KB |
testcase_07 | AC | 157 ms
11,208 KB |
testcase_08 | AC | 156 ms
11,188 KB |
testcase_09 | AC | 158 ms
11,196 KB |
testcase_10 | AC | 17 ms
8,084 KB |
testcase_11 | WA | - |
testcase_12 | AC | 21 ms
8,276 KB |
testcase_13 | AC | 23 ms
8,432 KB |
testcase_14 | AC | 28 ms
8,004 KB |
testcase_15 | AC | 25 ms
8,476 KB |
testcase_16 | AC | 42 ms
8,544 KB |
testcase_17 | AC | 34 ms
8,520 KB |
testcase_18 | AC | 38 ms
8,456 KB |
testcase_19 | AC | 43 ms
8,592 KB |
testcase_20 | AC | 20 ms
8,088 KB |
ソースコード
from heapq import heappush, heappop def dijkstra(y, x): dp = [[float('inf')] * N for _ in range(N)] dp[0][0] = 0 hq = [(0, y, x)] while(hq): h, sy, sx = heappop(hq) if dp[sy][sx] < h: continue for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]: ny = sy + dy nx = sx + dx if 0 <= ny < N and 0 <= nx < N and dp[ny][nx] > h + sand_area[ny][nx]: dp[ny][nx] = h + sand_area[ny][nx] heappush(hq, (h + sand_area[ny][nx], ny, nx)) return dp N, V, Ox, Oy = map(int, input().split()) Ox -= 1 Oy -= 1 sand_area = [list(map(int, input().split())) for _ in range(N)] dp1 = dijkstra(0, 0) if Ox == Oy == -1: if dp1[N - 1][N - 1] < V: print("YES") else: print("NO") exit() dp2 = dijkstra(Oy, Ox) if dp1[N - 1][N - 1] < V or (V - dp1[Oy][Ox]) * 2 > dp2[N - 1][N - 1]: print("YES") else: print("NO")