結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-04 03:47:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 86,784 KB
最終ジャッジ日時 2024-04-21 22:59:43
合計ジャッジ時間 6,293 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 43 ms
52,480 KB
testcase_03 AC 41 ms
51,968 KB
testcase_04 AC 43 ms
51,840 KB
testcase_05 AC 42 ms
52,224 KB
testcase_06 AC 42 ms
52,096 KB
testcase_07 AC 43 ms
51,968 KB
testcase_08 AC 44 ms
52,224 KB
testcase_09 AC 42 ms
52,352 KB
testcase_10 AC 41 ms
52,352 KB
testcase_11 AC 46 ms
52,608 KB
testcase_12 AC 45 ms
52,480 KB
testcase_13 AC 43 ms
51,840 KB
testcase_14 AC 122 ms
84,736 KB
testcase_15 AC 138 ms
86,784 KB
testcase_16 AC 90 ms
79,104 KB
testcase_17 AC 44 ms
52,736 KB
testcase_18 AC 100 ms
81,664 KB
testcase_19 AC 108 ms
81,792 KB
testcase_20 AC 134 ms
86,784 KB
testcase_21 AC 104 ms
81,280 KB
testcase_22 AC 80 ms
77,056 KB
testcase_23 AC 117 ms
84,224 KB
testcase_24 AC 82 ms
77,952 KB
testcase_25 AC 102 ms
81,280 KB
testcase_26 AC 127 ms
84,352 KB
testcase_27 AC 115 ms
83,968 KB
testcase_28 AC 113 ms
84,096 KB
testcase_29 AC 131 ms
86,784 KB
testcase_30 AC 55 ms
62,208 KB
testcase_31 AC 50 ms
58,752 KB
testcase_32 AC 99 ms
81,152 KB
testcase_33 AC 103 ms
81,152 KB
testcase_34 AC 89 ms
78,976 KB
testcase_35 AC 115 ms
84,224 KB
testcase_36 AC 60 ms
63,360 KB
testcase_37 AC 105 ms
81,408 KB
testcase_38 AC 106 ms
81,536 KB
testcase_39 AC 68 ms
73,984 KB
testcase_40 AC 127 ms
84,352 KB
testcase_41 AC 80 ms
78,336 KB
testcase_42 AC 119 ms
84,352 KB
testcase_43 AC 89 ms
79,232 KB
testcase_44 AC 117 ms
84,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0