結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-06-23 17:16:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 967 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 90,848 KB
最終ジャッジ日時 2024-04-25 23:01:54
合計ジャッジ時間 14,963 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,724 KB
testcase_01 AC 38 ms
53,016 KB
testcase_02 AC 37 ms
53,008 KB
testcase_03 AC 39 ms
52,976 KB
testcase_04 AC 48 ms
62,004 KB
testcase_05 AC 62 ms
70,036 KB
testcase_06 AC 60 ms
70,692 KB
testcase_07 AC 51 ms
65,036 KB
testcase_08 AC 46 ms
60,984 KB
testcase_09 AC 38 ms
53,452 KB
testcase_10 AC 39 ms
53,924 KB
testcase_11 AC 66 ms
72,888 KB
testcase_12 AC 653 ms
90,848 KB
testcase_13 AC 946 ms
89,824 KB
testcase_14 AC 39 ms
54,656 KB
testcase_15 AC 929 ms
90,032 KB
testcase_16 AC 492 ms
84,396 KB
testcase_17 AC 786 ms
89,816 KB
testcase_18 AC 705 ms
88,020 KB
testcase_19 AC 719 ms
88,820 KB
testcase_20 AC 967 ms
90,196 KB
testcase_21 AC 964 ms
90,436 KB
testcase_22 AC 961 ms
90,176 KB
testcase_23 AC 162 ms
78,572 KB
testcase_24 AC 339 ms
81,708 KB
testcase_25 AC 702 ms
87,932 KB
testcase_26 AC 578 ms
85,776 KB
testcase_27 AC 501 ms
84,224 KB
testcase_28 AC 803 ms
90,212 KB
testcase_29 AC 429 ms
83,196 KB
testcase_30 AC 249 ms
79,220 KB
testcase_31 AC 219 ms
79,392 KB
testcase_32 AC 535 ms
85,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Vector2:
	def __init__(self, x: int, y: int):
		self.x = x
		self.y = y

	def __lt__(self, other):
		return area(self, other) > 0

def area(v1: Vector2, v2: Vector2) -> int:
	return v1.x * v2.y - v1.y * v2.x

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


n = int(input())
vector = []
for _ in [0] * n:
	x, y = map(int, input().split())
	if(x == 0 and y == 0):
		continue
	if(y < 0):
		x = -x
		y = -y
	vector.append(Vector2(x, y))
vector.sort()

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

def count():
	global ans, last, x
	a, s = k, 0
	if(x < 0):
		a, x = -a, -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, k = 0, 1
for v in vector[::-1]:
	x, y = v.x, v.y
	count()

last, k = 0, -1
for v in vector:
	x, y = v.x, v.y
	count()

print(ans)
0