結果

問題 No.186 中華風 (Easy)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-15 13:36:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 477 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 8,804 KB
最終ジャッジ日時 2023-09-27 00:49:13
合計ジャッジ時間 6,148 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 212 ms
8,580 KB
testcase_01 AC 108 ms
8,600 KB
testcase_02 AC 104 ms
8,752 KB
testcase_03 AC 20 ms
8,752 KB
testcase_04 AC 225 ms
8,756 KB
testcase_05 AC 203 ms
8,560 KB
testcase_06 AC 308 ms
8,748 KB
testcase_07 AC 258 ms
8,600 KB
testcase_08 AC 382 ms
8,596 KB
testcase_09 AC 373 ms
8,572 KB
testcase_10 AC 306 ms
8,596 KB
testcase_11 AC 477 ms
8,632 KB
testcase_12 AC 131 ms
8,552 KB
testcase_13 AC 153 ms
8,572 KB
testcase_14 AC 173 ms
8,584 KB
testcase_15 AC 33 ms
8,692 KB
testcase_16 AC 165 ms
8,660 KB
testcase_17 AC 114 ms
8,628 KB
testcase_18 AC 67 ms
8,592 KB
testcase_19 AC 252 ms
8,564 KB
testcase_20 AC 91 ms
8,804 KB
testcase_21 AC 219 ms
8,572 KB
testcase_22 AC 247 ms
8,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import collections
import math


Equation = collections.namedtuple("Equation", "x y")
NOSOL = -1


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


def solve(eq1, eq2, eq3):
    for i in range(eq2.y + 1):
        cand12 = eq1.x + eq1.y * i
        if cand12 > 0 and cand12 % eq2.y == eq2.x:
            sol12 = cand12
            lcm12 = lcm(eq1.y, eq2.y)
            break
    else:
        return NOSOL
    for j in range(eq3.y + 2):
        cand123 = sol12 + lcm12 * j
        if cand123 > 0 and cand123 % eq3.y == eq3.x:
            return cand123
    else:
        return NOSOL


def main():
    eq1 = Equation(*map(int, input().split()))
    eq2 = Equation(*map(int, input().split()))
    eq3 = Equation(*map(int, input().split()))
    print(solve(eq1, eq2, eq3))


if __name__ == '__main__':
    main()
0