結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー rpy3cpprpy3cpp
提出日時 2015-12-14 02:35:23
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 792 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 21,180 KB
最終ジャッジ日時 2023-09-21 03:13:46
合計ジャッジ時間 7,025 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,332 KB
testcase_01 AC 18 ms
8,412 KB
testcase_02 AC 16 ms
8,260 KB
testcase_03 AC 16 ms
8,264 KB
testcase_04 AC 16 ms
8,264 KB
testcase_05 AC 16 ms
8,436 KB
testcase_06 AC 16 ms
8,136 KB
testcase_07 AC 16 ms
8,388 KB
testcase_08 AC 16 ms
8,256 KB
testcase_09 AC 16 ms
8,256 KB
testcase_10 AC 16 ms
8,360 KB
testcase_11 AC 16 ms
8,268 KB
testcase_12 AC 16 ms
8,276 KB
testcase_13 AC 16 ms
8,260 KB
testcase_14 AC 201 ms
16,140 KB
testcase_15 AC 282 ms
21,180 KB
testcase_16 AC 117 ms
13,364 KB
testcase_17 AC 17 ms
8,292 KB
testcase_18 AC 142 ms
14,408 KB
testcase_19 AC 183 ms
16,464 KB
testcase_20 AC 274 ms
20,784 KB
testcase_21 AC 169 ms
15,724 KB
testcase_22 AC 59 ms
10,336 KB
testcase_23 AC 237 ms
19,044 KB
testcase_24 AC 70 ms
10,924 KB
testcase_25 AC 158 ms
15,200 KB
testcase_26 AC 266 ms
20,272 KB
testcase_27 AC 199 ms
17,364 KB
testcase_28 AC 198 ms
17,160 KB
testcase_29 AC 281 ms
21,124 KB
testcase_30 AC 21 ms
8,664 KB
testcase_31 AC 19 ms
8,008 KB
testcase_32 AC 152 ms
14,664 KB
testcase_33 AC 144 ms
14,320 KB
testcase_34 AC 110 ms
12,848 KB
testcase_35 AC 220 ms
18,028 KB
testcase_36 AC 23 ms
8,856 KB
testcase_37 AC 175 ms
16,152 KB
testcase_38 AC 144 ms
14,696 KB
testcase_39 AC 55 ms
10,164 KB
testcase_40 AC 265 ms
20,000 KB
testcase_41 AC 80 ms
11,344 KB
testcase_42 AC 225 ms
18,620 KB
testcase_43 AC 117 ms
13,340 KB
testcase_44 AC 208 ms
17,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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