結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー kimiyuki
提出日時 2016-11-22 18:27:34
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,344 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-11-27 09:40:53
合計ジャッジ時間 11,674 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other WA * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
from fractions import Fraction
from collections import defaultdict
import math
def lcm(a, b):
    return a * b // math.gcd(a, b)
def qlcm(p, q):
    a = p.numerator * q.denominator
    b = p.denominator * q.numerator
    c = p.denominator * q.denominator
    return Fraction(lcm(a, b), c)
def dir(v, t):
    x = v * t % 2
    return x < 1
def pos(v, t):
    x = v * t % 2
    return min(x, 2 - x)
t1 = int(input())
t2 = int(input())
t3 = int(input())
v1 = Fraction(2, t1)
v2 = Fraction(2, t2)
v3 = Fraction(2, t3)
t12 = lcm(t1, t2)
t = Fraction(0)
x = pos(v1, t)
ans = float('inf')
while t == 0 or x != 0:
    # update t
    d1 = dir(v1, t)
    d2 = dir(v2, t)
    if d1 == d2 == True: # right
        l = 2 * (1 - x)
    elif d1 == d2 == False: # left
        l = 2 * x
    else:
        l = 2
    t += l / (v1 + v2)
    x = pos(v1, t)
    # check P3
    y = pos(v3, t)
    for is_right in range(2):
        if is_right == x < y:
            dy = x + 1 + y
        else:
            dy = abs(x - y)
        dt = dy / v3
        if dt == 0 or (t12 - t3) % dt == 0:
            if dt == 0:
                k = 0
            else:
                k = (t12 - t3) / dt
            # print(t + t12 * k,  t + dt + t3 * k, k)
            if t + t12 * k == t + dt + t3 * k:
                ans = min(ans, t + t12 * k)
print(ans)
0