結果
問題 |
No.849 yuki国の分割統治
|
ユーザー |
![]() |
提出日時 | 2020-03-18 12:52:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 198 ms / 2,000 ms |
コード長 | 1,015 bytes |
コンパイル時間 | 750 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 35,264 KB |
最終ジャッジ日時 | 2024-12-14 01:43:57 |
合計ジャッジ時間 | 6,490 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#!/usr/bin/env python3.8 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from math import gcd # %% a, b, c, d = map(int, readline().split()) N = int(readline()) m = map(int, read().split()) X, Y = zip(*zip(m, m)) # %% def fund_transform(a, b, c, d): while True: if a < c: a, c = c, a b, d = d, b if c == 0: if a == 0: b = abs(gcd(b, d)) d = 0 elif d == 0: pass else: d = abs(d) b %= d return a, b, c, d n = a // c a -= n * c b -= n * d def calc_key(x, y): if not a: y %= b return b * x + y n = x // a x -= a * n y -= b * n if not d: return a * y + x y %= d return a * y + x # %% a, b, c, d = fund_transform(a, b, c, d) keys = (calc_key(x, y) for x, y in zip(X, Y)) print(len(set(keys)))