結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-02-21 23:02:36
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,215 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 82,232 KB
実行使用メモリ 93,236 KB
最終ジャッジ日時 2024-04-25 22:56:53
合計ジャッジ時間 13,196 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
56,448 KB
testcase_01 AC 40 ms
55,484 KB
testcase_02 AC 42 ms
55,628 KB
testcase_03 AC 42 ms
56,904 KB
testcase_04 AC 49 ms
65,072 KB
testcase_05 AC 63 ms
74,296 KB
testcase_06 AC 62 ms
72,588 KB
testcase_07 AC 54 ms
67,976 KB
testcase_08 AC 47 ms
63,640 KB
testcase_09 AC 43 ms
56,944 KB
testcase_10 AC 40 ms
55,236 KB
testcase_11 AC 64 ms
74,172 KB
testcase_12 AC 528 ms
93,236 KB
testcase_13 AC 813 ms
92,180 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 418 ms
86,232 KB
testcase_17 AC 707 ms
91,580 KB
testcase_18 AC 603 ms
90,404 KB
testcase_19 AC 630 ms
90,748 KB
testcase_20 AC 842 ms
92,860 KB
testcase_21 AC 826 ms
92,184 KB
testcase_22 AC 856 ms
92,864 KB
testcase_23 AC 143 ms
79,076 KB
testcase_24 AC 292 ms
83,020 KB
testcase_25 AC 585 ms
90,524 KB
testcase_26 AC 504 ms
86,984 KB
testcase_27 AC 429 ms
86,552 KB
testcase_28 AC 692 ms
92,192 KB
testcase_29 AC 367 ms
85,112 KB
testcase_30 AC 216 ms
80,340 KB
testcase_31 AC 188 ms
80,484 KB
testcase_32 AC 469 ms
86,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import cmp_to_key
from math import gcd
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7


def floor_sum(n, m, a, b):
	if(m == 0):
		return 0
	res = 0
	while(True):
		if(a >= m or a < 0):
			res += n * (n - 1) * (a // m) // 2
			a %= m
		if(b >= m or b < 0):
			res += n * (b // m)
			b %= m
		y_max = a * n + b
		if(y_max < m):
			break
		n, b, m, a = y_max // m, y_max % m, a, m
	return res   

def arg_sort(v1, v2):
	x1, y1 = v1
	x2, y2 = v2
	if(x1 * y2 == x2 * y1):
		return 0
	elif(x1 * y2 - x2 * y1 < 0):
		return 1
	else:
		return -1

n = int(input())
v = []
for _ in [0] * n:
	x, y = map(int, input().split())
	if(y < 0):
		x = -x;		y = -y
	v.append((x, y))
v.sort(key = cmp_to_key(arg_sort))

if(n == 1):
	print((gcd(v[0][0], v[0][1]) + 1) % mod)
	exit(0)

ans = 1
for x, y in v:
	ans += gcd(abs(x), y)
	ans %= mod

last = 0
for x, y in v[::-1]:
	a = 1
	s = 0
	if(x < 0):
		a = -1
		x = -x
	s += floor_sum(x, x, y, x * last) % mod
	s %= mod
	ans += mod + a * s
	ans %= mod
	last += y
	last %= mod

last = 0
for x, y in v:
	a = -1
	s = 0
	if(x < 0):
		a = 1
		x = -x
	s += floor_sum(x, x, y, x * last) % mod
	s %= mod
	ans += mod + a * s
	ans %= mod
	last += y
	last %= mod

print(ans)
0