結果
| 問題 |
No.859 路線A、路線B、路線C
|
| コンテスト | |
| ユーザー |
qwewe
|
| 提出日時 | 2025-05-14 12:54:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,731 bytes |
| コンパイル時間 | 448 ms |
| コンパイル使用メモリ | 82,648 KB |
| 実行使用メモリ | 54,372 KB |
| 最終ジャッジ日時 | 2025-05-14 12:55:30 |
| 合計ジャッジ時間 | 1,398 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 WA * 5 |
ソースコード
x, y, z = map(int, input().split())
S0, t0 = input().split()
t0 = int(t0)
S1, t1 = input().split()
t1 = int(t1)
if S0 == S1:
print(abs(t0 - t1))
else:
def get_line_info(line, x, y, z):
if line == 'A':
first_node = 0
last_node = 3
count = x
elif line == 'B':
first_node = 1
last_node = 4
count = y
else: # 'C'
first_node = 5
last_node = 2
count = z
return first_node, last_node, count
x_line = S0
y_line = S1
x_first, x_last, x_count = get_line_info(x_line, x, y, z)
y_first, y_last, y_count = get_line_info(y_line, x, y, z)
# Calculate all four possible paths and take the minimum
# Path 1: X1 to Y1
cost_x_to_x1 = abs(t0 - 1)
delta = (y_first - x_first) % 6
cost_x1_to_y1 = min(delta, 6 - delta)
cost_y1_to_y = abs(t1 - 1)
total1 = cost_x_to_x1 + cost_x1_to_y1 + cost_y1_to_y
# Path 2: X1 to Yy
cost_x_to_x1 = abs(t0 - 1)
delta = (y_last - x_first) % 6
cost_x1_to_yy = min(delta, 6 - delta)
cost_yy_to_y = abs(t1 - y_count)
total2 = cost_x_to_x1 + cost_x1_to_yy + cost_yy_to_y
# Path 3: Xx to Y1
cost_x_to_xx = abs(x_count - t0)
delta = (y_first - x_last) % 6
cost_xx_to_y1 = min(delta, 6 - delta)
cost_y1_to_y = abs(t1 - 1)
total3 = cost_x_to_xx + cost_xx_to_y1 + cost_y1_to_y
# Path 4: Xx to Yy
cost_x_to_xx = abs(x_count - t0)
delta = (y_last - x_last) % 6
cost_xx_to_yy = min(delta, 6 - delta)
cost_yy_to_y = abs(t1 - y_count)
total4 = cost_x_to_xx + cost_xx_to_yy + cost_yy_to_y
min_total = min(total1, total2, total3, total4)
print(min_total)
qwewe