結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー rpy3cpprpy3cpp
提出日時 2015-12-14 02:33:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 791 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 21,176 KB
最終ジャッジ日時 2023-10-13 16:06:44
合計ジャッジ時間 7,391 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 17 ms
8,328 KB
testcase_02 AC 16 ms
8,348 KB
testcase_03 AC 16 ms
8,240 KB
testcase_04 AC 16 ms
8,340 KB
testcase_05 RE -
testcase_06 AC 16 ms
8,348 KB
testcase_07 AC 16 ms
8,344 KB
testcase_08 AC 16 ms
8,176 KB
testcase_09 AC 16 ms
8,392 KB
testcase_10 AC 15 ms
8,176 KB
testcase_11 AC 16 ms
8,176 KB
testcase_12 AC 16 ms
8,240 KB
testcase_13 AC 15 ms
8,316 KB
testcase_14 AC 202 ms
16,108 KB
testcase_15 AC 283 ms
21,020 KB
testcase_16 AC 118 ms
13,352 KB
testcase_17 AC 17 ms
8,368 KB
testcase_18 AC 143 ms
14,388 KB
testcase_19 AC 185 ms
16,688 KB
testcase_20 AC 276 ms
20,796 KB
testcase_21 AC 170 ms
15,768 KB
testcase_22 AC 59 ms
10,464 KB
testcase_23 AC 232 ms
19,032 KB
testcase_24 AC 70 ms
10,968 KB
testcase_25 AC 159 ms
15,328 KB
testcase_26 AC 264 ms
20,296 KB
testcase_27 AC 202 ms
17,492 KB
testcase_28 AC 198 ms
16,916 KB
testcase_29 AC 284 ms
21,176 KB
testcase_30 AC 22 ms
8,480 KB
testcase_31 AC 19 ms
8,444 KB
testcase_32 AC 150 ms
14,536 KB
testcase_33 AC 144 ms
14,616 KB
testcase_34 AC 108 ms
13,000 KB
testcase_35 AC 221 ms
18,004 KB
testcase_36 AC 23 ms
8,568 KB
testcase_37 AC 171 ms
16,068 KB
testcase_38 AC 144 ms
14,592 KB
testcase_39 AC 53 ms
10,144 KB
testcase_40 AC 264 ms
20,020 KB
testcase_41 AC 82 ms
11,304 KB
testcase_42 AC 224 ms
18,568 KB
testcase_43 AC 117 ms
13,328 KB
testcase_44 AC 206 ms
17,432 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 len(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