結果
問題 | No.20 砂漠のオアシス |
ユーザー | ayaoni |
提出日時 | 2020-12-22 15:15:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,322 bytes |
コンパイル時間 | 161 ms |
コンパイル使用メモリ | 81,804 KB |
実行使用メモリ | 120,812 KB |
最終ジャッジ日時 | 2023-10-21 12:56:50 |
合計ジャッジ時間 | 6,583 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,608 KB |
testcase_01 | AC | 46 ms
57,656 KB |
testcase_02 | AC | 49 ms
55,608 KB |
testcase_03 | AC | 152 ms
79,364 KB |
testcase_04 | AC | 222 ms
80,484 KB |
testcase_05 | AC | 530 ms
116,000 KB |
testcase_06 | AC | 538 ms
120,812 KB |
testcase_07 | AC | 568 ms
120,376 KB |
testcase_08 | AC | 532 ms
120,576 KB |
testcase_09 | AC | 556 ms
119,620 KB |
testcase_10 | WA | - |
testcase_11 | AC | 41 ms
55,616 KB |
testcase_12 | WA | - |
testcase_13 | AC | 172 ms
80,044 KB |
testcase_14 | AC | 199 ms
81,272 KB |
testcase_15 | AC | 198 ms
80,452 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 289 ms
86,980 KB |
testcase_20 | AC | 129 ms
77,872 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,Ox,Oy = 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')