結果
問題 | No.20 砂漠のオアシス |
ユーザー | kohei2019 |
提出日時 | 2021-02-10 10:15:54 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,796 bytes |
コンパイル時間 | 256 ms |
コンパイル使用メモリ | 87,108 KB |
実行使用メモリ | 84,016 KB |
最終ジャッジ日時 | 2023-09-22 03:24:43 |
合計ジャッジ時間 | 4,727 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
71,396 KB |
testcase_01 | AC | 78 ms
71,300 KB |
testcase_02 | AC | 76 ms
71,324 KB |
testcase_03 | AC | 155 ms
78,116 KB |
testcase_04 | AC | 130 ms
78,208 KB |
testcase_05 | AC | 358 ms
84,016 KB |
testcase_06 | AC | 186 ms
81,156 KB |
testcase_07 | AC | 287 ms
82,060 KB |
testcase_08 | AC | 167 ms
80,284 KB |
testcase_09 | AC | 262 ms
81,012 KB |
testcase_10 | WA | - |
testcase_11 | AC | 77 ms
71,236 KB |
testcase_12 | WA | - |
testcase_13 | AC | 148 ms
78,692 KB |
testcase_14 | AC | 184 ms
79,808 KB |
testcase_15 | AC | 164 ms
79,088 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 187 ms
79,632 KB |
testcase_20 | AC | 133 ms
77,768 KB |
ソースコード
import heapq import sys #ダイクストラ法 N,V,ox,oy = map(int,input().split()) ox -= 1 oy -= 1 lsL = [list(map(int,input().split())) for i in range(N)] dxy =[(1,0),(0,1),(-1,0),(0,-1)] #オアシスを通らない場合 lsHP = [[-float('INF')]*(N) for i in range(N)] lsHP[0][0] = V used = [[False]*(N) for i in range(N)] h = [(-lsHP[0][0],0,0)] heapq.heapify(h) while h: cost,x,y = heapq.heappop(h) if used[x][y]: continue used[x][y] = True for dx,dy in dxy: if 0<=x+dx<N and 0<=y+dy<N: if used[x+dx][y+dy]: continue if (lsHP[x][y] - lsL[x+dx][y+dy]) < 0: continue if lsHP[x+dx][y+dy] < (lsHP[x][y] - lsL[x+dx][y+dy]): lsHP[x+dx][y+dy] = (lsHP[x][y] - lsL[x+dx][y+dy]) heapq.heappush(h,(-lsHP[x+dx][y+dy],x+dx,y+dy)) if lsHP[-1][-1] > 0: print('YES') sys.exit() if ox != -1 and oy != -1: #オアシスを通る場合 lsHP2 = [[-float('INF')]*(N) for i in range(N)] lsHP2[ox][oy] = lsHP[ox][oy]*2 used = [[False]*(N) for i in range(N)] h = [(-lsHP[ox][oy],ox,oy)] heapq.heapify(h) while h: cost,x,y = heapq.heappop(h) if used[x][y]: continue used[x][y] = True for dx,dy in dxy: if 0<=x+dx<N and 0<=y+dy<N: if used[x+dx][y+dy]: continue if (lsHP2[x][y] - lsL[x+dx][y+dy]) < 0: continue if lsHP2[x+dx][y+dy] < (lsHP2[x][y] - lsL[x+dx][y+dy]): lsHP2[x+dx][y+dy] = (lsHP2[x][y] - lsL[x+dx][y+dy]) heapq.heappush(h,(-lsHP2[x+dx][y+dy],x+dx,y+dy)) if lsHP2[-1][-1] > 0: print('YES') else: print('NO') else: print('NO')