結果

問題 No.849 yuki国の分割統治
ユーザー titiatitia
提出日時 2019-07-12 07:17:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 50,252 KB
最終ジャッジ日時 2024-04-16 09:26:52
合計ジャッジ時間 7,425 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 32 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 33 ms
11,008 KB
testcase_04 AC 33 ms
11,008 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 32 ms
11,008 KB
testcase_07 AC 302 ms
44,544 KB
testcase_08 AC 276 ms
40,192 KB
testcase_09 AC 307 ms
42,496 KB
testcase_10 AC 311 ms
42,368 KB
testcase_11 AC 262 ms
38,272 KB
testcase_12 AC 292 ms
37,760 KB
testcase_13 AC 312 ms
43,776 KB
testcase_14 AC 290 ms
39,168 KB
testcase_15 AC 257 ms
38,656 KB
testcase_16 AC 306 ms
46,592 KB
testcase_17 AC 306 ms
43,904 KB
testcase_18 AC 313 ms
46,464 KB
testcase_19 AC 320 ms
44,544 KB
testcase_20 AC 335 ms
46,464 KB
testcase_21 AC 300 ms
37,632 KB
testcase_22 AC 317 ms
46,464 KB
testcase_23 AC 321 ms
46,464 KB
testcase_24 AC 303 ms
44,544 KB
testcase_25 AC 308 ms
50,252 KB
testcase_26 AC 31 ms
10,880 KB
testcase_27 AC 31 ms
11,136 KB
testcase_28 AC 31 ms
11,008 KB
testcase_29 AC 31 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

input = sys.stdin.readline

def lcm(a,b):
    return a*b//math.gcd(a,b)

a,b,c,d=map(int,input().split())
N=int(input())
P=[list(map(int,input().split())) for i in range(N)]


if a*d-b*c==0 and a!=0:
    a1=math.gcd(a,c)
    b1=b//(a//a1)

    def rep_point(p,q):
        k=p//a1

        return p-k*a1,q-k*b1

    Q=[rep_point(P[i][0],P[i][1]) for i in range(N)]

    print(len(set(Q)))
    sys.exit()
    
elif a*d-b*c==0:
    b1=math.gcd(b,d)
    a1=a//(b//b1)

    def rep_point(p,q):
        k=q//b1

        return p-k*a1,q-k*b1

    Q=[rep_point(P[i][0],P[i][1]) for i in range(N)]

    print(len(set(Q)))
    sys.exit()

x = lcm(a,c)

if a==0:
    t=abs(b)
    a,b=c,d
    
    
else:

    while c!=0:
        if a>c:
            a,b,c,d=c,d,a,b
            
        r,q=divmod(c,a)
        c,d=q,d-b*r

    t = abs(d)   

def rep_point(p,q):
    k=p//a

    p-=k*a
    q-=k*b

    q=q%t

    return p,q

Q=[rep_point(P[i][0],P[i][1]) for i in range(N)]

print(len(set(Q)))

0