結果

問題 No.1486 ロボット
ユーザー otsunekootsuneko
提出日時 2021-04-23 22:41:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 16,012 KB
最終ジャッジ日時 2023-09-17 12:45:20
合計ジャッジ時間 2,237 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,844 KB
testcase_01 AC 16 ms
7,784 KB
testcase_02 AC 17 ms
7,776 KB
testcase_03 AC 16 ms
7,780 KB
testcase_04 AC 16 ms
7,800 KB
testcase_05 AC 16 ms
7,716 KB
testcase_06 AC 17 ms
7,820 KB
testcase_07 AC 461 ms
16,012 KB
testcase_08 AC 16 ms
7,796 KB
testcase_09 AC 16 ms
7,800 KB
testcase_10 AC 48 ms
8,540 KB
testcase_11 AC 45 ms
8,488 KB
testcase_12 AC 18 ms
8,284 KB
testcase_13 AC 17 ms
7,768 KB
testcase_14 AC 142 ms
11,288 KB
testcase_15 AC 43 ms
8,840 KB
testcase_16 AC 80 ms
9,800 KB
testcase_17 AC 67 ms
9,644 KB
testcase_18 AC 76 ms
9,412 KB
testcase_19 AC 33 ms
8,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

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

A,B,C,D,E = map(int,input().split())
n = lcm(A+B,C+D)
end = min(n,E)
robot = [False]*end
flag1 = flag2 = False
cnt1 = B
cnt2 = D
for i in range(end):
    if flag1:
        if cnt1%A == 0:
            flag1 = False
            cnt1 -= A
    else:
        if cnt1%B == 0:
            flag1 = True
            cnt1 -= B
    if flag2:
        if cnt2%C == 0:
            flag2 = False
            cnt2 -= C
    else:
        if cnt2%D == 0:
            flag2 = True
            cnt2 -= D
    if flag1 and flag2:
        robot[i] = True
    cnt1 += 1
    cnt2 += 1

ans = robot.count(True)
if n < E:
    ans *= E//n
    remain = E%n
    ans += robot[:remain].count(True)

print(ans)
0