結果
問題 | No.859 路線A、路線B、路線C |
ユーザー |
![]() |
提出日時 | 2019-08-08 20:47:52 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 106 ms / 1,000 ms |
コード長 | 2,168 bytes |
コンパイル時間 | 210 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 15,912 KB |
最終ジャッジ日時 | 2024-07-18 20:56:36 |
合計ジャッジ時間 | 2,240 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
import unittestdef check_constants(x, y, z, s0, t0, s1, t1):assert 1 <= x <= 10**9assert 1 <= y <= 10**9assert 1 <= z <= 10 ** 9if s0 == 'A':assert 1 <= t0 <= xelif s0 == 'B':assert 1 <= t0 <= yelif s0 == 'C':assert 1 <= t0 <= zelse:assert False, 'unreachable'if s1 == 'A':assert 1 <= t1 <= xelif s1 == 'B':assert 1 <= t1 <= yelif s1 == 'C':assert 1 <= t1 <= zelse:assert False, 'unreachable'assert s0 != s1 or t0 != t1def get_route_length(route, x, y, z):if route == 'A':return xelif route == 'B':return yelse:return zdef solve(x, y, z, s0, t0, s1, t1):min_cost = float('inf')if s0 == s1:if t0 > t1:t0, t1 = t1, t0min_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_costdef 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)self.assertEqual(solve(10, 1, 1000, 'C', 1, 'C', 1000), 2)if __name__ == "__main__":# unittest.main()main()