結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー maspy
提出日時 2020-03-04 18:45:50
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 33,868 KB
最終ジャッジ日時 2024-10-14 00:23:33
合計ジャッジ時間 4,946 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from math import gcd

# %%
P, Q = map(int, readline().split())
N = int(readline())
m = map(int, read().split())
XY = list(zip(m, m))

# %%
d = gcd(P, Q)
if d == 0:
    answer = sum(x == y == 0 for x, y in XY)
    print(answer)
    exit()
P //= d
Q //= d
is_even = (P + Q) % 2 == 0


# %%
def check(X, Y, d, is_even):
    if X % d != 0:
        return False
    if Y % d != 0:
        return False
    X //= d
    Y //= d
    if is_even:
        return (X + Y) % 2 == 0
    else:
        return True


# %%
answer = sum(check(x, y, d, is_even) for x, y in XY)
print(answer)
0