結果

問題 No.859 路線A、路線B、路線C
ユーザー McGregorshMcGregorsh
提出日時 2023-07-10 21:12:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 262 ms / 1,000 ms
コード長 3,036 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 89,452 KB
最終ジャッジ日時 2023-10-10 01:23:51
合計ジャッジ時間 5,265 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 262 ms
89,452 KB
testcase_01 AC 253 ms
89,288 KB
testcase_02 AC 254 ms
89,212 KB
testcase_03 AC 259 ms
89,372 KB
testcase_04 AC 259 ms
89,208 KB
testcase_05 AC 254 ms
89,432 KB
testcase_06 AC 258 ms
89,388 KB
testcase_07 AC 260 ms
89,312 KB
testcase_08 AC 254 ms
89,384 KB
testcase_09 AC 255 ms
89,332 KB
testcase_10 AC 259 ms
89,140 KB
testcase_11 AC 259 ms
89,392 KB
testcase_12 AC 252 ms
89,152 KB
testcase_13 AC 254 ms
89,104 KB
testcase_14 AC 262 ms
89,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

###ダイクストラ###

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)[-1]
   
   if s1 == s2:
   	  ans = min(ans, abs(t1-t2))
   print(ans)
   
if __name__ == '__main__':
    main()












0