結果

問題 No.321 (P,Q)-サンタと街の子供たち
コンテスト
ユーザー rpy3cpp
提出日時 2015-12-14 02:35:23
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 792 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 539 ms
コンパイル使用メモリ 20,696 KB
実行使用メモリ 27,100 KB
最終ジャッジ日時 2026-03-28 11:59:08
合計ジャッジ時間 8,869 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math


def read_data():
    P, Q = map(int, input().split())
    N = int(input())
    xys = []
    for n in range(N):
        x, y = map(int, input().split())
        xys.append((x, y))
    return P, Q, N, xys


def solve(P, Q, N, xys):
    if P == 0 and Q == 0:
        return sum(1 for x, y in xys if x == 0 and y == 0)
    if P == 0 or Q == 0:
        GCD = P + Q
        odd_cycle = True
    else:
        GCD = math.gcd(P, Q)
        LCM = P * Q // GCD
        odd_cycle = (LCM // P + LCM // Q) % 2
    count = 0
    for x, y in xys:
        mx, rx = divmod(x, GCD)
        my, ry = divmod(y, GCD)
        if rx == 0 and ry == 0:
            if odd_cycle or ((mx + my) % 2 == 0):
                count += 1
    return count


P, Q, N, xys = read_data()
print(solve(P, Q, N, xys))
0