結果

問題 No.1999 Lattice Teleportation
ユーザー MasKoaTSMasKoaTS
提出日時 2022-02-21 21:46:45
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,230 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 93,020 KB
最終ジャッジ日時 2024-04-25 22:56:25
合計ジャッジ時間 13,882 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,696 KB
testcase_01 AC 45 ms
55,880 KB
testcase_02 RE -
testcase_03 AC 42 ms
56,236 KB
testcase_04 AC 49 ms
64,016 KB
testcase_05 AC 65 ms
72,128 KB
testcase_06 AC 64 ms
73,004 KB
testcase_07 AC 56 ms
67,756 KB
testcase_08 AC 49 ms
63,320 KB
testcase_09 AC 42 ms
55,292 KB
testcase_10 AC 42 ms
56,324 KB
testcase_11 AC 69 ms
73,972 KB
testcase_12 AC 576 ms
93,020 KB
testcase_13 AC 869 ms
92,080 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 457 ms
86,792 KB
testcase_17 AC 710 ms
91,328 KB
testcase_18 AC 653 ms
89,980 KB
testcase_19 AC 695 ms
90,492 KB
testcase_20 AC 874 ms
92,468 KB
testcase_21 AC 937 ms
92,440 KB
testcase_22 AC 907 ms
92,724 KB
testcase_23 AC 155 ms
79,276 KB
testcase_24 AC 330 ms
82,696 KB
testcase_25 AC 720 ms
90,468 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#嘘解法

from functools import cmp_to_key
from math import gcd
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
rev2 = pow(2, mod - 2, mod)

def floor_sum(n, m, a, b):
	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