結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー mkawa2mkawa2
提出日時 2020-01-28 16:34:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,255 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 11,100 KB
実行使用メモリ 276,296 KB
最終ジャッジ日時 2023-10-13 17:51:32
合計ジャッジ時間 14,367 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def lcm(a,b):
    return a*b//gcd(a,b)

def gcd(a,b):
    while b:a,b=b,a%b
    return a

import fractions as f

def main():
    # 往復にかかる時間[2,3,4]とする
    # 往復の距離を最小公倍数の12とすると速さは[12/2,12/3,12/4]=[6,4,3]
    # P1,P2だけに注目すると2点が出会うのは2点の進んだ距離の「和」が2Lの倍数になったとき
    # つまり時間をtとすると6t+4t=12n まとめて10t=12n
    # またP1がP2に追いつくのは2点の進んだ距離の「差」が2Lの倍数になったとき
    # つまり時間をtとすると6t-4t=12m まとめて2t=12m
    # P1とP3についても同様にすると 9t=12p 3t=12q
    # P1とP2が重なるtとP1とP3が重なるtのうち共通したものが3点が重なる時間
    #  つまり(10t=12nまたは2t=12m)かつ(9t=12pまたは3t=12q)を満たす最小のt
    # 少なくともlcm(2,3,4)秒後には必ず重なるので、そこまで調べればいい
    tt=[II() for _ in range(3)]
    tt.sort()
    l=lcm(tt[0],lcm(tt[1],tt[2]))
    v1,v2,v3=l//tt[0],l//tt[1],l//tt[2]
    s0=set()
    for i in range(1,10**12):
        t=f.Fraction(l*i,v1+v2)
        if t>l:break
        s0.add(t)
        t=f.Fraction(l*i,v1-v2)
        s0.add(t)
    s1=set()
    for i in range(1,10**12):
        t=f.Fraction(l*i,v1+v3)
        if t>l:break
        s1.add(t)
        t=f.Fraction(l*i,v1-v3)
        s1.add(t)
    s0&=s1
    ans=min(s0)
    print(ans.numerator,"/",ans.denominator,sep="")

main()
0