結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | McGregorsh |
提出日時 | 2023-07-10 20:50:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,983 bytes |
コンパイル時間 | 425 ms |
コンパイル使用メモリ | 87,220 KB |
実行使用メモリ | 89,640 KB |
最終ジャッジ日時 | 2023-10-10 01:23:46 |
合計ジャッジ時間 | 6,043 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 255 ms
89,388 KB |
testcase_01 | AC | 253 ms
89,412 KB |
testcase_02 | AC | 253 ms
89,428 KB |
testcase_03 | AC | 255 ms
89,384 KB |
testcase_04 | AC | 258 ms
89,436 KB |
testcase_05 | AC | 256 ms
89,444 KB |
testcase_06 | AC | 255 ms
89,424 KB |
testcase_07 | AC | 256 ms
89,156 KB |
testcase_08 | AC | 252 ms
89,336 KB |
testcase_09 | AC | 251 ms
89,204 KB |
testcase_10 | AC | 257 ms
89,332 KB |
testcase_11 | WA | - |
testcase_12 | AC | 259 ms
89,388 KB |
testcase_13 | AC | 258 ms
89,216 KB |
testcase_14 | AC | 255 ms
89,456 KB |
ソースコード
###ダイクストラ### def daikusutora(N, G, s): dist = [INF] * N que = [(0, s)] dist[s] = 0 while que: c, v = heappop(que) if dist[v] < c: continue for t, cost in G[v]: if dist[v] + cost < dist[t]: dist[t] = dist[v] + cost heappush(que, (dist[t], t)) return dist import sys from sys import stdin from fractions import Fraction import math from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement, permutations from bisect import bisect, bisect_left, bisect_right from functools import reduce, lru_cache from decimal import Decimal, getcontext, ROUND_HALF_UP def i_input(): return int(stdin.readline()) def i_map(): return map(int, stdin.readline().split()) def i_list(): return list(i_map()) def s_input(): return stdin.readline()[:-1] def s_map(): return s_input().split() def s_list(): return list(s_map()) def lcm(a, b): return a * b // gcd(a, b) def get_distance(x1, y1, x2, y2): d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) return d def rotate(table): n_fild = [] for x in zip(*table[::-1]): n_fild.append(x) return n_fild sys.setrecursionlimit(10 ** 7) INF = float('inf') MOD = 10 ** 9 + 7 MOD2 = 998244353 alpa = 'abcdefghijklmnopqrstuvwxyz' ALPA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def main(): x, y, z = i_map() s1, t1 = s_map() t1 = int(t1) s2, t2 = s_map() t2 = int(t2) G = [[] for i in range(8)] G[0].append([1, x-1]) G[1].append([0, x-1]) G[2].append([3, y-1]) G[3].append([2, y-1]) G[4].append([5, z-1]) G[5].append([4, z-1]) G[0].append([2, 1]) G[2].append([0, 1]) G[0].append([4, 1]) G[4].append([0, 1]) G[2].append([4, 1]) G[4].append([2, 1]) G[1].append([3, 1]) G[3].append([1, 1]) G[1].append([5, 1]) G[5].append([1, 1]) G[3].append([5, 1]) G[5].append([3, 1]) if s1 == 'A': G[6].append([0, t1-1]) G[0].append([6, t1-1]) G[6].append([1, x-t1]) G[1].append([6, x-t1]) elif s1 == 'B': G[6].append([2, t1-1]) G[2].append([6, t1-1]) G[6].append([3, y-t1]) G[3].append([6, y-t1]) else: G[6].append([4, t1-1]) G[4].append([6, t1-1]) G[6].append([5, z-t1]) G[5].append([6, z-t1]) if s2 == 'A': G[7].append([0, t2-1]) G[0].append([7, t2-1]) G[7].append([1, x-t2]) G[1].append([7, x-t2]) elif s2 == 'B': G[7].append([2, t2-1]) G[2].append([7, t2-1]) G[7].append([3, y-t2]) G[3].append([7, y-t2]) else: G[7].append([4, t2-1]) G[4].append([7, t2-1]) G[7].append([5, z-t2]) G[5].append([7, z-t2]) ans = daikusutora(8, G, 6) print(ans[-1]) if __name__ == '__main__': main()