結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー NoneNone
提出日時 2021-04-28 11:44:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,866 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 77,916 KB
最終ジャッジ日時 2023-09-21 12:05:19
合計ジャッジ時間 9,068 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,316 KB
testcase_01 AC 76 ms
71,112 KB
testcase_02 WA -
testcase_03 AC 76 ms
71,640 KB
testcase_04 AC 74 ms
71,608 KB
testcase_05 AC 75 ms
71,428 KB
testcase_06 WA -
testcase_07 AC 77 ms
71,312 KB
testcase_08 WA -
testcase_09 AC 77 ms
71,340 KB
testcase_10 AC 76 ms
71,516 KB
testcase_11 WA -
testcase_12 AC 76 ms
71,620 KB
testcase_13 AC 74 ms
71,576 KB
testcase_14 AC 134 ms
77,520 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 135 ms
77,480 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 149 ms
77,556 KB
testcase_27 WA -
testcase_28 AC 139 ms
77,540 KB
testcase_29 WA -
testcase_30 AC 103 ms
76,596 KB
testcase_31 WA -
testcase_32 AC 127 ms
77,500 KB
testcase_33 AC 130 ms
77,740 KB
testcase_34 AC 125 ms
77,420 KB
testcase_35 WA -
testcase_36 AC 115 ms
77,016 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 149 ms
77,504 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def my_gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def gcd2(array):
    temp = array[0]
    for a in array[1:]:
        temp = gcd(temp, a)
    return temp

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

def lcm2(array):
    temp = 1
    for a in array:
        temp = lcm(temp, a)
    return temp

def gcd_ext(a0,b0):
    """
    ax + by = gcd(a,b) を満たす|x|が最小の(x,y)
    一般解は (x+k*b//gcd(a,b),y-k*a//gcd(a,b)) と表される

    備考:
    ax + by = G (=m*gcd(a,b)) の場合は、
    単に m=G//gcd を (x,y) に掛ければよい
    """
    a,b=abs(a0),abs(b0)
    sign_a,sing_b=(a0>0)-(a0<0),(b0>0)-(b0<0)
    x0, y0, x, y = 0, 1, 1, 0
    while b!=0:
        q=a//b
        a,b=b,a%b
        x0, y0, x, y = x-q*x0, y-q*y0, x0, y0
    return (x*sign_a,y*sing_b)

def bezout_identity(a,b,G,cut=10**6,positive=True):
    """
    ベズーの等式
    ax + by = G
    を満たす解(x,y)
    G は gcdの倍数でなければならない

    計算量: O(cut)
    """
    x,y = gcd_ext(a,b)
    g=a*x+b*y
    if G%g: return []
    m=G//g
    xmax,xmin=cut,-cut*(positive==False)
    kmax,kmin=(xmax-x*m)//abs(b//g), (xmin-x*m-1)//abs(b//g)+1
    table=[]
    if positive: # 正数解のみ
        for k in range(kmin,kmax+1):
            xx,yy=x*m+k*b//g,y*m-k*a//g
            if xx>cut or xx<0 or yy>cut or yy<0: continue
            table.append((xx,yy))
        return table
    else:
        for k in range(kmin,kmax+1):
            xx,yy=x*m+k*b//g,y*m-k*a//g
            if abs(xx)>cut or abs(yy)>cut: continue
            table.append((xx,yy))
        return table

def bezout_identity_lower_bound(a,b,G,x0=0,equal=True):
    """
    ax + by = G を満たすxが x0 以上(より大きい)のうちで最小の(x,y)
    一般解は (x+k*b//gcd(a,b),y-k*a//gcd(a,b)) と表される
    """
    x,y = gcd_ext(a,b)
    g=a*x+b*y

    if G%g: return None
    m=G//g
    bg=abs(b//g)
    if equal==True:
        if b>=0:
            k=(x0-x*m+bg-1)//bg
        else:
            k=(x*m-x0)//bg
    else:
        if b>=0:
            k=(x0-x*m+bg)//bg
        else:
            k=(x*m-x0-1)//bg
    return x*m+k*b//g,y*m-k*a//g

def bezout_identity_upper_bound(a,b,G,x0=0,equal=True):
    """
    ax + by = G を満たす xが x0 以下(未満)のうちで最大の(x,y)
    一般解は (x+k*b//gcd(a,b),y-k*a//gcd(a,b)) と表される
    """
    x,y = gcd_ext(a,b)
    g=a*x+b*y

    if G%g: return None
    m=G//g
    bg=abs(b//g)
    if equal==True:
        if b>=0:
            k=(x0-x*m)//bg
        else:
            k=(x*m-x0-1)//bg+1
    else:
        if b>=0:
            k=(x0-x*m+bg-1)//bg-1
        else:
            k=(x*m-x0)//bg+1

    return x*m+k*b//g,y*m-k*a//g

def mod_inv(a,MOD):
    """
    gcd(a,MOD)=1 を満たす必要あり
    """
    x,y=gcd_ext(a,MOD)
    return x%MOD

def mod_solve(a,b,MOD):
    """
    ax=b (mod MOD)
    """
    x,y=gcd_ext(a,MOD)
    g=a*x+MOD*y
    a_inv=x%MOD
    if b%g: return None
    a,b,MOD=a//g,b//g,MOD//g
    return b*a_inv%MOD

######################################################

from math import gcd
P,Q=map(int, input().split())
N=int(input())
cnt=0
if P!=0 and Q!=0:
    g=gcd(P,Q)
    a,b=gcd_ext(P,Q)
    for _ in range(N):
        x,y=map(int, input().split())
        if x%g==0 and y%g==0:
            mx=x//g
            my=y//g
            if (((x//g+y//g)*a%2==0 and (x//g+y//g)*b%2==0)) or ((x//g)*(b//g)+(y//g)*(a//g))%2==1:
                cnt+=1
elif P==0 and Q!=0:
    for _ in range(N):
        x,y=map(int, input().split())
        if x==0 and y%Q==0:
            cnt+=1
elif Q==0 and P!=0:
    for _ in range(N):
        x,y=map(int, input().split())
        if y==0 and x%P==0:
            cnt+=1
else:
    for _ in range(N):
        x,y=map(int, input().split())
        if x==0 and y==0:
            cnt+=1
print(cnt)
0