結果

問題 No.321 (P,Q)-サンタと街の子供たち
コンテスト
ユーザー lam6er
提出日時 2025-03-31 17:51:40
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,022 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 223 ms
コンパイル使用メモリ 96,492 KB
実行使用メモリ 111,124 KB
最終ジャッジ日時 2026-07-08 05:25:54
合計ジャッジ時間 7,117 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
import math

def main():
    input = sys.stdin.read().split()
    idx = 0
    P = int(input[idx]); idx +=1
    Q = int(input[idx]); idx +=1
    N = int(input[idx]); idx +=1
    points = []
    for _ in range(N):
        x = int(input[idx]); idx +=1
        y = int(input[idx]); idx +=1
        points.append((x, y))
    
    count = 0
    
    if P == 0 and Q == 0:
        for x, y in points:
            if x == 0 and y == 0:
                count +=1
        print(count)
        return
    
    # Compute d = gcd(P, Q)
    d = math.gcd(P, Q)
    
    # Compute g = gcd(P+Q, P-Q)
    a = P + Q
    b = P - Q
    g = math.gcd(abs(a), abs(b))
    
    for x, y in points:
        # Check if x and y are multiples of d
        if x % d != 0 or y % d != 0:
            continue
        
        # Check sum and difference
        s = x + y
        t = x - y
        
        if s % g != 0 or t % g != 0:
            continue
        
        count +=1
    
    print(count)

if __name__ == "__main__":
    main()
0