結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー |
|
提出日時 | 2015-12-14 02:35:23 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 315 ms / 2,000 ms |
コード長 | 792 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 23,808 KB |
最終ジャッジ日時 | 2024-07-06 21:52:26 |
合計ジャッジ時間 | 7,419 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
ソースコード
import mathdef 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, xysdef 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 + Qodd_cycle = Trueelse:GCD = math.gcd(P, Q)LCM = P * Q // GCDodd_cycle = (LCM // P + LCM // Q) % 2count = 0for 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 += 1return countP, Q, N, xys = read_data()print(solve(P, Q, N, xys))