結果
問題 |
No.859 路線A、路線B、路線C
|
ユーザー |
![]() |
提出日時 | 2019-08-08 20:33:50 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 104 ms / 1,000 ms |
コード長 | 2,069 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 15,872 KB |
最終ジャッジ日時 | 2024-07-18 20:56:22 |
合計ジャッジ時間 | 2,593 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
import unittest def check_constants(x, y, z, s0, t0, s1, t1): assert 1 <= x <= 10**9 assert 1 <= y <= 10**9 assert 1 <= z <= 10 ** 9 if s0 == 'A': assert 1 <= t0 <= x elif s0 == 'B': assert 1 <= t0 <= y elif s0 == 'C': assert 1 <= t0 <= z else: assert False, 'unreachable' if s1 == 'A': assert 1 <= t1 <= x elif s1 == 'B': assert 1 <= t1 <= y elif s1 == 'C': assert 1 <= t1 <= z else: assert False, 'unreachable' def get_route_length(route, x, y, z): if route == 'A': return x elif route == 'B': return y else: return z def solve(x, y, z, s0, t0, s1, t1): min_cost = float('inf') if s0 == s1: if t0 > t1: t0, t1 = t1, t0 min_cost = min( t1 - t0, t0 + min(x, y, z) + get_route_length(s1, x, y, z) - t1 ) else: min_cost = min( t0 + t1 - 1, get_route_length(s0, x, y, z) - t0 + get_route_length(s1, x, y, z) - t1 + 1, t0 + min(x, y, z) + get_route_length(s1, x, y, z) - t1, t1 + min(x, y, z) + get_route_length(s0, x, y, z) - t0, ) return min_cost def main(): x, y, z = map(int, input().split()) s0, t0 = input().split() s1, t1 = input().split() t0 = int(t0) t1 = int(t1) check_constants(x, y, z, s0, t0, s1, t1) result = solve(x, y, z, s0, t0, s1, t1) print(result) class Test3084(unittest.TestCase): def test3084(self): self.assertEqual(solve(3, 4, 5, 'A', 1, 'B', 1), 1) self.assertEqual(solve(3, 4, 5, 'C', 5, 'C', 2), 3) self.assertEqual(solve(5, 1, 5, 'A', 1, 'C', 5), 2) self.assertEqual(solve(10, 100, 1000, 'A', 1, 'C', 5), 5) self.assertEqual(solve(10, 100, 1000, 'A', 1, 'C', 995), 15) self.assertEqual(solve(10, 1, 1000, 'A', 10, 'C', 5), 6) self.assertEqual(solve(10, 1, 1000, 'A', 1, 'C', 995), 7) if __name__ == "__main__": # unittest.main() main()