結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-21 22:00:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 975 ms / 2,000 ms
コード長 1,227 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 93,080 KB
最終ジャッジ日時 2024-04-25 22:59:29
合計ジャッジ時間 14,749 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,988 KB
testcase_01 AC 45 ms
55,936 KB
testcase_02 AC 45 ms
55,660 KB
testcase_03 AC 45 ms
56,608 KB
testcase_04 AC 55 ms
65,004 KB
testcase_05 AC 70 ms
72,920 KB
testcase_06 AC 70 ms
72,596 KB
testcase_07 AC 59 ms
67,208 KB
testcase_08 AC 53 ms
64,584 KB
testcase_09 AC 46 ms
56,412 KB
testcase_10 AC 46 ms
55,828 KB
testcase_11 AC 72 ms
73,644 KB
testcase_12 AC 616 ms
93,080 KB
testcase_13 AC 953 ms
91,880 KB
testcase_14 AC 44 ms
56,220 KB
testcase_15 AC 949 ms
91,928 KB
testcase_16 AC 497 ms
86,244 KB
testcase_17 AC 780 ms
91,240 KB
testcase_18 AC 700 ms
90,028 KB
testcase_19 AC 731 ms
90,744 KB
testcase_20 AC 975 ms
92,700 KB
testcase_21 AC 963 ms
92,776 KB
testcase_22 AC 958 ms
92,184 KB
testcase_23 AC 156 ms
79,356 KB
testcase_24 AC 332 ms
83,148 KB
testcase_25 AC 679 ms
90,560 KB
testcase_26 AC 572 ms
87,332 KB
testcase_27 AC 491 ms
86,924 KB
testcase_28 AC 791 ms
91,940 KB
testcase_29 AC 409 ms
84,768 KB
testcase_30 AC 237 ms
80,604 KB
testcase_31 AC 209 ms
79,964 KB
testcase_32 AC 529 ms
86,668 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(x == 0 and y == 0):
		n -= 1
		continue
	if(y < 0):
		x = -x;		y = -y
	v.append((x, y))
v.sort(key = cmp_to_key(arg_sort))

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, 0) % mod + x * last % mod
	s %= mod
	ans += mod + a * s
	ans %= mod
	last += mod + 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, 0) % mod + x * last % mod
	s %= mod
	ans += mod + a * s
	ans %= mod
	last += mod + y
	last %= mod

print(ans)
0