結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー |
![]() |
提出日時 | 2021-01-04 03:47:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 950 bytes |
コンパイル時間 | 351 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 86,912 KB |
最終ジャッジ日時 | 2024-10-13 21:26:17 |
合計ジャッジ時間 | 5,750 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
from math import gcd import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) P, Q = map(int, input().split()) if P > Q: P, Q = Q, P N = int(input()) XY = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = 0 if P == 0 and Q == 0: for x, y in XY: if x == 0 and y == 0: ans += 1 elif P == 0: for x, y in XY: if x % Q == 0 and y % Q == 0: ans += 1 elif gcd(P, Q) == 1: if (P + Q) % 2 == 1: ans = N else: for x, y in XY: if (x + y) % 2 == 0: ans += 1 else: g = gcd(P, Q) P //= g Q //= g if (P + Q) % 2 == 1: for x, y in XY: if x % g == 0 and y % g == 0: ans += 1 else: for x, y in XY: if x % g == 0 and y % g == 0: x //= g y //= g if (x + y) % 2 == 0: ans += 1 print(ans)