結果
問題 | No.20 砂漠のオアシス |
ユーザー | yaoshimax |
提出日時 | 2015-04-12 16:49:41 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 760 ms / 5,000 ms |
コード長 | 1,368 bytes |
コンパイル時間 | 139 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 10,296 KB |
最終ジャッジ日時 | 2024-04-21 06:26:21 |
合計ジャッジ時間 | 5,329 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
6,812 KB |
testcase_01 | AC | 11 ms
6,940 KB |
testcase_02 | AC | 11 ms
6,940 KB |
testcase_03 | AC | 29 ms
6,944 KB |
testcase_04 | AC | 49 ms
6,944 KB |
testcase_05 | AC | 760 ms
10,296 KB |
testcase_06 | AC | 726 ms
9,344 KB |
testcase_07 | AC | 718 ms
9,088 KB |
testcase_08 | AC | 708 ms
9,216 KB |
testcase_09 | AC | 716 ms
9,088 KB |
testcase_10 | AC | 11 ms
6,944 KB |
testcase_11 | AC | 11 ms
6,940 KB |
testcase_12 | AC | 37 ms
6,940 KB |
testcase_13 | AC | 43 ms
6,940 KB |
testcase_14 | AC | 68 ms
6,944 KB |
testcase_15 | AC | 53 ms
6,940 KB |
testcase_16 | AC | 141 ms
7,040 KB |
testcase_17 | AC | 99 ms
6,940 KB |
testcase_18 | AC | 120 ms
7,040 KB |
testcase_19 | AC | 144 ms
7,040 KB |
testcase_20 | AC | 25 ms
6,940 KB |
ソースコード
from heapq import heappush, heappop N,V,Ox,Oy=map(int,raw_input().split()) Ox,Oy=Oy,Ox L=[[0 for i in range(N)] for j in range(N)] for i in range(N): L[i] = map(int,raw_input().split()) P=[[-1 for i in range(N)] for j in range(N)] pq=[] heappush(pq,(0,0,0)) d1 = [1,0,-1,0] d2 = [0,1,0,-1] while len(pq) != 0: dist,x,y = heappop(pq) if P[x][y] != -1: continue P[x][y]=dist for dx,dy in zip(d1,d2): nx = x+dx ny = y+dy if nx>=0 and ny >= 0 and nx <N and ny <N: heappush(pq,(dist+L[nx][ny],nx,ny)) P2=[[-1 for i in range(N)] for j in range(N)] pq2=[] Ox-=1 Oy-=1 if Ox >= 0 and Oy >= 0 and Ox <N and Oy <N: heappush(pq2,(0,Ox,Oy)) while len(pq2)!=0: dist,x,y = heappop(pq2) if P2[x][y] != -1: continue P2[x][y]=dist for dx,dy in zip(d1,d2): nx = x+dx ny = y+dy; if nx>=0 and ny >= 0 and nx <N and ny <N: heappush(pq2,(dist+L[nx][ny],nx,ny)) #for i in range(N): # for j in range(N): # print P[i][j], # print #print #for i in range(N): # for j in range(N): # print P2[i][j], # print #print P[N-1][N-1], P[Ox][Oy], P2[N-1][N-1] if P[N-1][N-1] < V: # print P[N-1][N-1] print "YES" elif P2[N-1][N-1]!=-1 and 2*(V-P[Ox][Oy])-P2[N-1][N-1] > 0: # print P[Ox][Oy], ",", P2[N-1][N-1] print "YES" else: print "NO"