結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー tjaketjake
提出日時 2015-12-16 12:41:21
言語 Python2
(2.7.18)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 6,612 KB
実行使用メモリ 6,168 KB
最終ジャッジ日時 2023-09-21 03:26:58
合計ジャッジ時間 7,950 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,052 KB
testcase_01 AC 11 ms
5,980 KB
testcase_02 AC 11 ms
5,916 KB
testcase_03 AC 12 ms
6,100 KB
testcase_04 AC 12 ms
5,980 KB
testcase_05 AC 12 ms
6,068 KB
testcase_06 AC 12 ms
5,980 KB
testcase_07 AC 12 ms
6,052 KB
testcase_08 AC 11 ms
5,984 KB
testcase_09 AC 11 ms
5,908 KB
testcase_10 AC 12 ms
6,160 KB
testcase_11 AC 11 ms
6,124 KB
testcase_12 AC 12 ms
5,976 KB
testcase_13 AC 12 ms
5,948 KB
testcase_14 AC 192 ms
6,072 KB
testcase_15 AC 274 ms
5,980 KB
testcase_16 AC 113 ms
5,980 KB
testcase_17 AC 13 ms
5,912 KB
testcase_18 AC 141 ms
5,996 KB
testcase_19 AC 183 ms
5,980 KB
testcase_20 AC 275 ms
6,008 KB
testcase_21 AC 233 ms
6,020 KB
testcase_22 AC 53 ms
6,132 KB
testcase_23 AC 336 ms
5,952 KB
testcase_24 AC 72 ms
6,072 KB
testcase_25 AC 150 ms
5,976 KB
testcase_26 AC 262 ms
5,980 KB
testcase_27 AC 197 ms
6,088 KB
testcase_28 AC 208 ms
6,080 KB
testcase_29 AC 395 ms
6,056 KB
testcase_30 AC 19 ms
6,132 KB
testcase_31 AC 14 ms
5,952 KB
testcase_32 AC 208 ms
6,024 KB
testcase_33 AC 151 ms
5,988 KB
testcase_34 AC 114 ms
5,960 KB
testcase_35 AC 307 ms
6,012 KB
testcase_36 AC 18 ms
5,988 KB
testcase_37 AC 183 ms
5,920 KB
testcase_38 AC 157 ms
5,960 KB
testcase_39 AC 65 ms
5,964 KB
testcase_40 AC 277 ms
5,912 KB
testcase_41 AC 104 ms
5,920 KB
testcase_42 AC 225 ms
6,168 KB
testcase_43 AC 123 ms
6,016 KB
testcase_44 AC 204 ms
6,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def extgcd(a, b):
    if b:
        d, y, x = extgcd(b, a%b)
        y -= (a/b)*x
        return d, x, y
    else:
        return a, 1, 0
inputs = lambda:map(int, raw_input().split())
p, q = inputs()
if p<q: p,q = q,p
g, a, b = extgcd(p, q)
n = input()
ans = 0
for i in xrange(n):
    xi, yi = inputs()
    if p==0:
        ans += (xi==yi==0)
    elif q==0:
        ans += (xi%p==0 and yi%p==0)
    else:
        if xi%g==0 and yi%g==0:
            xr = xi/g; yr = yi/g
            x  = xr*a; y = xr*b
            dx = q/g; dy = -p/g
            z = yr*b; w = yr*a
            dz = p/g; dw = -q/g
            #print x, dx, y, dy
            #print z, dz, w, dw
            if(((x+z)%2==0 and (y+w)%2==0) or
               ((x+z+dx)%2==0 and (y+w+dy)%2==0) or
               ((x+z+dz)%2==0 and (y+w+dw)%2==0) or
               ((x+z+dx+dz)%2==0 and (y+w+dy+dw)%2==0)):
                ans += 1
print ans
0