結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-02-22 23:13:49
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,183 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 92,896 KB
最終ジャッジ日時 2024-04-25 22:59:05
合計ジャッジ時間 14,481 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,848 KB
testcase_01 AC 44 ms
56,672 KB
testcase_02 AC 45 ms
56,108 KB
testcase_03 AC 44 ms
55,696 KB
testcase_04 AC 54 ms
64,184 KB
testcase_05 AC 68 ms
72,592 KB
testcase_06 AC 66 ms
72,080 KB
testcase_07 AC 59 ms
68,728 KB
testcase_08 AC 52 ms
63,520 KB
testcase_09 AC 44 ms
55,484 KB
testcase_10 AC 44 ms
56,572 KB
testcase_11 AC 69 ms
73,632 KB
testcase_12 AC 617 ms
92,896 KB
testcase_13 AC 917 ms
91,888 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 484 ms
86,356 KB
testcase_17 AC 768 ms
91,572 KB
testcase_18 AC 679 ms
89,988 KB
testcase_19 AC 714 ms
91,140 KB
testcase_20 AC 952 ms
92,580 KB
testcase_21 AC 966 ms
92,620 KB
testcase_22 AC 955 ms
92,276 KB
testcase_23 AC 160 ms
79,076 KB
testcase_24 AC 345 ms
82,472 KB
testcase_25 AC 705 ms
90,352 KB
testcase_26 AC 589 ms
87,028 KB
testcase_27 AC 503 ms
86,572 KB
testcase_28 AC 820 ms
92,448 KB
testcase_29 AC 422 ms
84,556 KB
testcase_30 AC 236 ms
80,672 KB
testcase_31 AC 211 ms
79,912 KB
testcase_32 AC 539 ms
86,964 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))

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