結果

問題 No.186 中華風 (Easy)
ユーザー mkawa2mkawa2
提出日時 2020-01-27 13:21:27
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 8,856 KB
最終ジャッジ日時 2023-09-27 00:58:15
合計ジャッジ時間 1,770 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,700 KB
testcase_01 AC 19 ms
8,804 KB
testcase_02 AC 20 ms
8,656 KB
testcase_03 AC 20 ms
8,804 KB
testcase_04 AC 20 ms
8,856 KB
testcase_05 AC 20 ms
8,708 KB
testcase_06 AC 20 ms
8,836 KB
testcase_07 AC 19 ms
8,732 KB
testcase_08 AC 20 ms
8,720 KB
testcase_09 AC 19 ms
8,800 KB
testcase_10 AC 20 ms
8,676 KB
testcase_11 AC 19 ms
8,704 KB
testcase_12 AC 19 ms
8,800 KB
testcase_13 AC 19 ms
8,684 KB
testcase_14 AC 19 ms
8,848 KB
testcase_15 AC 19 ms
8,804 KB
testcase_16 AC 20 ms
8,816 KB
testcase_17 AC 19 ms
8,652 KB
testcase_18 AC 20 ms
8,832 KB
testcase_19 AC 20 ms
8,800 KB
testcase_20 AC 19 ms
8,676 KB
testcase_21 AC 19 ms
8,848 KB
testcase_22 AC 19 ms
8,844 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 gcd(a,b):
    while b:a,b=b,a%b
    return a

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

def extgcd(a,b,c):
    if b==0:return c//a,0,abs(a)
    x,y,g=extgcd(b,a%b,c)
    return y,x-y*(a//b),g

def main():
    x1,y1=MI()
    x2,y2=MI()
    x3,y3=MI()
    p,q,g=extgcd(y1,-y2,x2-x1)
    if (x2-x1)%g>0:
        print(-1)
        exit()
    x4=y1*p+x1
    y4=lcm(y1,y2)
    s,r,g=extgcd(y4,-y3,x3-x4)
    if (x3-x4)%g>0:
        print(-1)
        exit()
    ans=(y4*s+x4-1)%lcm(y4,y3)+1
    print(ans)

main()
0