結果

問題 No.849 yuki国の分割統治
ユーザー kimiyuki
提出日時 2019-07-05 23:50:44
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 40,188 KB
最終ジャッジ日時 2024-10-06 23:24:08
合計ジャッジ時間 9,185 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import math

def gcd2(a, b, c, d):
    while a:
        k = c // a
        a, c = c - k * a, a
        b, d = d - k * b, b
    return a, b, c, d


def solve(a, b, c, d, n, p):
    a, b, c, d = gcd2(a, b, c, d)
    assert a == 0

    found = set()
    for x, y in p:
        if c:
            k = x // c
            x1 = x - k * c
            y1 = y - k * d
            if b:
                y1 %= b
        else:
            x1 = x
            y1 = y % math.gcd(b, d)
        found.add((x1, y1))
    return len(found)

def main():
    a, b, c, d = map(int, input().split())
    n = int(input())
    p = [tuple(map(int, input().split())) for _ in range(n)]
    print(solve(a, b, c, d, n, p))

if __name__ == '__main__':
    main()
0