結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-02-21 23:03:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,215 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 37,488 KB
最終ジャッジ日時 2024-04-25 22:56:59
合計ジャッジ時間 6,071 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
18,080 KB
testcase_01 AC 31 ms
11,136 KB
testcase_02 AC 31 ms
11,136 KB
testcase_03 AC 31 ms
11,136 KB
testcase_04 AC 37 ms
11,008 KB
testcase_05 AC 61 ms
11,008 KB
testcase_06 AC 57 ms
11,136 KB
testcase_07 AC 45 ms
11,136 KB
testcase_08 AC 37 ms
11,136 KB
testcase_09 AC 31 ms
11,136 KB
testcase_10 AC 31 ms
11,136 KB
testcase_11 AC 44 ms
11,136 KB
testcase_12 AC 1,421 ms
30,544 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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