結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー mkawa2mkawa2
提出日時 2020-01-28 17:21:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,493 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 8,824 KB
最終ジャッジ日時 2023-10-13 17:55:06
合計ジャッジ時間 2,576 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,708 KB
testcase_01 AC 19 ms
8,716 KB
testcase_02 AC 21 ms
8,620 KB
testcase_03 AC 18 ms
8,824 KB
testcase_04 AC 17 ms
8,804 KB
testcase_05 AC 17 ms
8,808 KB
testcase_06 AC 17 ms
8,716 KB
testcase_07 AC 17 ms
8,688 KB
testcase_08 AC 18 ms
8,644 KB
testcase_09 AC 17 ms
8,656 KB
testcase_10 AC 18 ms
8,804 KB
testcase_11 AC 17 ms
8,652 KB
testcase_12 AC 18 ms
8,700 KB
testcase_13 AC 18 ms
8,620 KB
testcase_14 AC 16 ms
8,752 KB
testcase_15 AC 18 ms
8,664 KB
testcase_16 AC 18 ms
8,648 KB
testcase_17 AC 17 ms
8,736 KB
testcase_18 AC 17 ms
8,716 KB
testcase_19 AC 18 ms
8,700 KB
testcase_20 AC 20 ms
8,708 KB
testcase_21 AC 19 ms
8,708 KB
testcase_22 AC 19 ms
8,652 KB
testcase_23 AC 20 ms
8,708 KB
testcase_24 AC 20 ms
8,740 KB
testcase_25 AC 18 ms
8,668 KB
testcase_26 AC 19 ms
8,736 KB
testcase_27 AC 17 ms
8,712 KB
testcase_28 AC 17 ms
8,652 KB
testcase_29 AC 17 ms
8,720 KB
testcase_30 AC 18 ms
8,656 KB
testcase_31 AC 17 ms
8,760 KB
testcase_32 AC 16 ms
8,652 KB
testcase_33 AC 18 ms
8,652 KB
testcase_34 AC 16 ms
8,712 KB
testcase_35 AC 17 ms
8,692 KB
testcase_36 AC 17 ms
8,656 KB
testcase_37 WA -
testcase_38 AC 17 ms
8,668 KB
testcase_39 AC 17 ms
8,648 KB
testcase_40 AC 17 ms
8,712 KB
testcase_41 AC 16 ms
8,764 KB
testcase_42 AC 17 ms
8,648 KB
testcase_43 AC 17 ms
8,732 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

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

def main():
    # 往復にかかる時間[2,3,4]とする
    # 往復の距離を1とすると速さは[1/2,1/3,1/4]
    # P1,P2だけに注目すると2点が出会うのは2点の進んだ距離の「和」が1の倍数、つまり整数になったとき
    # つまり時間をtとすると(1/2 + 1/3)t=n nは自然数
    # またP1がP2に追いつくのは2点の進んだ距離の「差」が整数になったとき
    # つまり時間をtとすると(1/2 - 1/3)t=m mは自然数
    # P1とP3についても同様にすると (1/2 + 1/4)t=p (1/2 - 1/4)t=q p,qは自然数
    # P1とP2が重なるtとP1とP3が重なるtのうち共通したものが3点が重なる時間
    # よって (1/2 + 1/3)t=n かつ (1/2 + 1/4)t=p
    # または (1/2 + 1/3)t=n かつ (1/2 - 1/4)t=q
    # または (1/2 - 1/3)t=n かつ (1/2 + 1/4)t=q
    # または (1/2 - 1/3)t=n かつ (1/2 - 1/4)t=q
    # が成り立てばよい。1番目のパターンを一般化すると
    # (1/t1 + 1/t2)t=n (1/t1 + 1/t3)t=m
    # tの分子lcm(t1,t2,t3) tの分母 (lcm/t1 + lcm/t2)と(lcm/t1 + lcm/t3)の最大公約数

    tt = [II() for _ in range(3)]
    tt.sort()
    t1, t2, t3 = tt
    l = lcm(t1, lcm(t2, t3))
    ans = []
    for pm1 in [-1, 1]:
        g = gcd(t1, t2)
        num1 = (t2 + pm1 * t1) // g
        den1 = t1 * t2 // g
        for pm2 in [-1, 1]:
            g = gcd(t1, t3)
            num2 = (t3 + pm2 * t1) // g
            den2 = t1 * t3 // g
            den = gcd(num1, num2)
            num = lcm(den1, den2)
            ans.append((num / den, num, den))
    ans.sort()
    print(ans[0][1], "/", ans[0][2], sep="")

main()
0