結果

問題 No.187 中華風 (Hard)
ユーザー flygonflygon
提出日時 2023-06-04 20:36:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 834 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 86,676 KB
実行使用メモリ 83,844 KB
最終ジャッジ日時 2023-08-28 08:24:19
合計ジャッジ時間 8,856 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
72,348 KB
testcase_01 AC 97 ms
72,248 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 91 ms
71,780 KB
testcase_18 AC 96 ms
72,388 KB
testcase_19 AC 93 ms
71,820 KB
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from collections import defaultdict, deque, Counter
import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline


def extgcd(a, b):
    if b == 0:
        return 1, 0, a
    q, r = a//b, a % b
    x, y, d = extgcd(b, r)
    s, t = y, x-y*q
    return s, t, d

def crt(b, m):
    r = 0
    M = 1
    for i in range(len(b)):
        s,t, d = extgcd(M, m[i])
        if (b[i] - r) % d != 0: 
            return [0, -1]
        lcm = M * m[i] // d
        r +=  M * ((b[i] - r) // d) * s
        M = lcm
        r %= M
    return r, M

n = int(input())   
b = []
m = []
for i in range(n):
    x,y = map(int,input().split())
    b.append(x)
    m.append(y)
r, M = crt(b,m)
if M != -1 and r != 0:
    print(r)
else:
    print(M)
0