結果
問題 | No.20 砂漠のオアシス |
ユーザー | ayaoni |
提出日時 | 2020-12-22 15:21:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 569 ms / 5,000 ms |
コード長 | 2,322 bytes |
コンパイル時間 | 270 ms |
コンパイル使用メモリ | 81,796 KB |
実行使用メモリ | 120,812 KB |
最終ジャッジ日時 | 2023-10-21 12:56:57 |
合計ジャッジ時間 | 6,419 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,616 KB |
testcase_01 | AC | 44 ms
57,664 KB |
testcase_02 | AC | 48 ms
55,616 KB |
testcase_03 | AC | 151 ms
79,360 KB |
testcase_04 | AC | 215 ms
80,484 KB |
testcase_05 | AC | 530 ms
115,996 KB |
testcase_06 | AC | 540 ms
120,812 KB |
testcase_07 | AC | 569 ms
120,276 KB |
testcase_08 | AC | 530 ms
120,572 KB |
testcase_09 | AC | 564 ms
119,620 KB |
testcase_10 | AC | 40 ms
55,616 KB |
testcase_11 | AC | 41 ms
55,616 KB |
testcase_12 | AC | 165 ms
79,708 KB |
testcase_13 | AC | 181 ms
80,044 KB |
testcase_14 | AC | 202 ms
81,272 KB |
testcase_15 | AC | 194 ms
80,452 KB |
testcase_16 | AC | 290 ms
86,676 KB |
testcase_17 | AC | 240 ms
83,244 KB |
testcase_18 | AC | 271 ms
84,688 KB |
testcase_19 | AC | 283 ms
86,980 KB |
testcase_20 | AC | 129 ms
77,876 KB |
ソースコード
import sys,collections,heapq sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) class Dijkstra: def __init__(self): self.e = collections.defaultdict(list) def add(self, u, v, d, directed=False): if directed is False: # 無向グラフの場合 self.e[u].append([v, d]) self.e[v].append([u, d]) else: # 有向グラフの場合 self.e[u].append([v, d]) def delete(self, u, v): self.e[u] = [_ for _ in self.e[u] if _[0] != v] self.e[v] = [_ for _ in self.e[v] if _[0] != u] def search(self, s): # sから各頂点までの最短距離 d = collections.defaultdict(lambda: float('inf')) d[s] = 0 q = [] heapq.heappush(q, (0, s)) v = collections.defaultdict(bool) while len(q): k, u = heapq.heappop(q) if v[u]: continue v[u] = True for uv, ud in self.e[u]: if v[uv]: continue vd = k + ud if d[uv] > vd: d[uv] = vd heapq.heappush(q, (vd, uv)) return d N,V,Oy,Ox = MI() L = [LI() for _ in range(N)] Di = Dijkstra() for i in range(N): for j in range(N): l = L[i][j] if i >= 1: Di.add((i-1,j),(i,j),l,directed=True) if i <= N-2: Di.add((i+1,j),(i,j),l,directed=True) if j >= 1: Di.add((i,j-1),(i,j),l,directed=True) if j <= N-2: Di.add((i,j+1),(i,j),l,directed=True) dist = Di.search((0,0)) if (Ox,Oy) == (0,0): if dist[(N-1,N-1)] < V: print('YES') else: print('NO') else: Ox -= 1 Oy -= 1 a = dist[(Ox,Oy)] b = Di.search((N-1,N-1))[(Ox,Oy)]-L[Ox][Oy]+L[-1][-1] c = dist[(N-1,N-1)] if c < V or (a < V and b < 2*(V-a)): print('YES') else: print('NO')