結果

問題 No.849 yuki国の分割統治
ユーザー kimiyukikimiyuki
提出日時 2019-07-05 23:50:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 423 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 40,128 KB
最終ジャッジ日時 2024-04-16 08:16:19
合計ジャッジ時間 9,134 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 30 ms
10,624 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 32 ms
10,624 KB
testcase_04 AC 33 ms
10,624 KB
testcase_05 AC 32 ms
10,752 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 388 ms
25,216 KB
testcase_08 AC 359 ms
28,644 KB
testcase_09 AC 369 ms
27,856 KB
testcase_10 AC 397 ms
25,856 KB
testcase_11 AC 340 ms
26,368 KB
testcase_12 AC 376 ms
24,704 KB
testcase_13 AC 395 ms
28,712 KB
testcase_14 AC 378 ms
25,600 KB
testcase_15 AC 339 ms
27,264 KB
testcase_16 AC 418 ms
34,428 KB
testcase_17 AC 376 ms
24,320 KB
testcase_18 AC 416 ms
34,900 KB
testcase_19 AC 423 ms
26,368 KB
testcase_20 AC 419 ms
31,740 KB
testcase_21 AC 384 ms
24,064 KB
testcase_22 AC 419 ms
33,528 KB
testcase_23 AC 409 ms
32,248 KB
testcase_24 AC 386 ms
26,112 KB
testcase_25 AC 413 ms
40,128 KB
testcase_26 AC 31 ms
10,624 KB
testcase_27 AC 31 ms
10,752 KB
testcase_28 AC 32 ms
10,624 KB
testcase_29 AC 31 ms
10,624 KB
権限があれば一括ダウンロードができます

ソースコード

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