結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー mkawa2mkawa2
提出日時 2020-01-28 17:22:54
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 2,226 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-10-13 17:55:13
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,580 KB
testcase_01 AC 20 ms
8,584 KB
testcase_02 AC 20 ms
8,692 KB
testcase_03 AC 20 ms
8,564 KB
testcase_04 AC 21 ms
8,600 KB
testcase_05 AC 21 ms
8,660 KB
testcase_06 AC 20 ms
8,676 KB
testcase_07 AC 20 ms
8,692 KB
testcase_08 AC 20 ms
8,676 KB
testcase_09 AC 21 ms
8,580 KB
testcase_10 AC 20 ms
8,636 KB
testcase_11 AC 20 ms
8,616 KB
testcase_12 AC 20 ms
8,660 KB
testcase_13 AC 20 ms
8,752 KB
testcase_14 AC 20 ms
8,552 KB
testcase_15 AC 20 ms
8,632 KB
testcase_16 AC 20 ms
8,556 KB
testcase_17 AC 21 ms
8,692 KB
testcase_18 AC 19 ms
8,660 KB
testcase_19 AC 20 ms
8,596 KB
testcase_20 AC 21 ms
8,704 KB
testcase_21 AC 20 ms
8,676 KB
testcase_22 AC 20 ms
8,744 KB
testcase_23 AC 20 ms
8,580 KB
testcase_24 AC 20 ms
8,664 KB
testcase_25 AC 20 ms
8,560 KB
testcase_26 AC 20 ms
8,692 KB
testcase_27 AC 20 ms
8,752 KB
testcase_28 AC 20 ms
8,760 KB
testcase_29 AC 20 ms
8,744 KB
testcase_30 AC 19 ms
8,584 KB
testcase_31 AC 20 ms
8,684 KB
testcase_32 AC 20 ms
8,632 KB
testcase_33 AC 20 ms
8,596 KB
testcase_34 AC 20 ms
8,584 KB
testcase_35 AC 20 ms
8,664 KB
testcase_36 AC 21 ms
8,660 KB
testcase_37 AC 20 ms
8,736 KB
testcase_38 AC 20 ms
8,580 KB
testcase_39 AC 20 ms
8,660 KB
testcase_40 AC 21 ms
8,684 KB
testcase_41 AC 20 ms
8,604 KB
testcase_42 AC 20 ms
8,648 KB
testcase_43 AC 20 ms
8,628 KB
testcase_44 AC 20 ms
8,744 KB
testcase_45 AC 20 ms
8,676 KB
権限があれば一括ダウンロードができます

ソースコード

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))
    mx=0
    for pm1 in [-1,1]:
        for pm2 in [-1,1]:
            d=gcd(l//t1+pm1*l//t2,l//t1+pm2*l//t3)
            if d>mx:mx=d
    g=gcd(l,mx)
    print(l//g,"/",mx//g,sep="")

main()
0