結果

問題 No.186 中華風 (Easy)
ユーザー rpy3cpprpy3cpp
提出日時 2015-09-18 19:53:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,006 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 8,004 KB
最終ジャッジ日時 2023-09-26 12:26:18
合計ジャッジ時間 1,501 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,800 KB
testcase_01 AC 17 ms
7,944 KB
testcase_02 AC 17 ms
7,828 KB
testcase_03 AC 18 ms
7,808 KB
testcase_04 AC 16 ms
8,004 KB
testcase_05 AC 17 ms
7,952 KB
testcase_06 AC 16 ms
7,884 KB
testcase_07 AC 16 ms
7,784 KB
testcase_08 AC 16 ms
7,928 KB
testcase_09 AC 16 ms
7,952 KB
testcase_10 AC 15 ms
7,884 KB
testcase_11 AC 16 ms
7,888 KB
testcase_12 AC 16 ms
7,828 KB
testcase_13 AC 17 ms
7,832 KB
testcase_14 AC 16 ms
7,844 KB
testcase_15 AC 16 ms
7,808 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 16 ms
7,856 KB
testcase_19 AC 16 ms
7,784 KB
testcase_20 AC 16 ms
7,860 KB
testcase_21 AC 16 ms
7,868 KB
testcase_22 AC 16 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    x1, y1 = map(int, input().split())
    x2, y2 = map(int, input().split())
    x3, y3 = map(int, input().split())
    return x1, y1, x2, y2, x3, y3


def gcd_ext(m: int, n: int) -> (int, int, int):
    '''拡張ユークリッドの互除法
    mx + ny = gcd(x, y)
    となる、gcd(x, y), x, y を返す。
    '''
    x, y, u, v = 1, 0, 0, 1
    while n:
        k, m = divmod(m, n)
        m, n = n, m
        x, y, u, v = u, v, x - u * k, y - v * k
    return m, x, y


def solve2(x1, y1, x2, y2):
    gcd, a, b = gcd_ext(y1, y2)
    lcm = y1 * y2 // gcd
    k, r = divmod(x1 - x2, gcd)
    if r != 0:
        return -1, lcm
    z = (x1 - k * a * y1) % lcm
    #  z = (x2 + k * b * y2) % lcm
    return z, lcm


def solve3(x1, y1, x2, y2, x3, y3):
    x12, y12 = solve2(x1, y1, x2, y2)
    if x12 == -1: return -1
    #  z % y12 = x12 and z % y3 = x3
    z, lcm = solve2(x12, y12, x3, y3)
    return z


x1, y1, x2, y2, x3, y3 = read_data()
print(solve3(x1, y1, x2, y2, x3, y3))
0