結果

問題 No.187 中華風 (Hard)
ユーザー vwxyzvwxyz
提出日時 2021-07-31 11:13:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 769 ms / 3,000 ms
コード長 1,592 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 10,808 KB
実行使用メモリ 10,964 KB
最終ジャッジ日時 2023-10-14 14:42:25
合計ジャッジ時間 9,977 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,608 KB
testcase_01 AC 30 ms
10,620 KB
testcase_02 AC 71 ms
10,752 KB
testcase_03 AC 75 ms
10,728 KB
testcase_04 AC 732 ms
10,732 KB
testcase_05 AC 700 ms
10,964 KB
testcase_06 AC 708 ms
10,824 KB
testcase_07 AC 690 ms
10,840 KB
testcase_08 AC 751 ms
10,792 KB
testcase_09 AC 767 ms
10,856 KB
testcase_10 AC 769 ms
10,812 KB
testcase_11 AC 707 ms
10,836 KB
testcase_12 AC 692 ms
10,808 KB
testcase_13 AC 31 ms
10,648 KB
testcase_14 AC 30 ms
10,620 KB
testcase_15 AC 63 ms
10,748 KB
testcase_16 AC 61 ms
10,652 KB
testcase_17 AC 32 ms
10,468 KB
testcase_18 AC 33 ms
10,604 KB
testcase_19 AC 31 ms
10,484 KB
testcase_20 AC 485 ms
10,712 KB
testcase_21 AC 31 ms
10,468 KB
testcase_22 AC 702 ms
10,828 KB
testcase_23 AC 30 ms
10,484 KB
testcase_24 AC 30 ms
10,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD, modf
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines


def CRT(lst_r,lst_m):
    r,m=lst_r[0],lst_m[0]
    for r0,m0 in zip(lst_r[1:],lst_m[1:]):
        if (r0,m0)==(-1,0):
            r,m=-1,0
            break
        r0%=m0
        g=math.gcd(m,m0)
        l=LCM(m,m0)
        if r%g!=r0%g:
            r,m=-1,0
            break
        r,m=(r0+m0*(((r-r0)//g)*Extended_Euclid(m0//g,m//g)[0]%(m//g)))%l,l
    return r,m

def LCM(n,m):
    if n or m:
        return abs(n)*abs(m)//math.gcd(n,m)
    return 0

def Extended_Euclid(n,m):
    stack=[]
    while m:
        stack.append((n,m))
        n,m=m,n%m
    if n>=0:
        x,y=1,0
    else:
        x,y=-1,0
    for i in range(len(stack)-1,-1,-1):
        n,m=stack[i]
        x,y=y,x-(n//m)*y
    return x,y

N=int(readline())
mod=10**9+7
X,Y=[],[]
for _ in range(N):
    x,y=map(int,readline().split())
    X.append(x)
    Y.append(y)
x,y=CRT(X,Y)
if x==-1:
    ans=-1
else:
    if x==0:
        x=y
    ans=x%mod
print(ans)
0