結果
問題 | No.1999 Lattice Teleportation |
ユーザー | MasKoaTS |
提出日時 | 2022-05-03 16:01:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 972 ms / 2,000 ms |
コード長 | 1,121 bytes |
コンパイル時間 | 147 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 93,336 KB |
最終ジャッジ日時 | 2024-04-25 23:00:26 |
合計ジャッジ時間 | 14,748 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
56,988 KB |
testcase_01 | AC | 44 ms
57,396 KB |
testcase_02 | AC | 44 ms
55,552 KB |
testcase_03 | AC | 44 ms
55,756 KB |
testcase_04 | AC | 53 ms
64,096 KB |
testcase_05 | AC | 68 ms
73,820 KB |
testcase_06 | AC | 66 ms
73,716 KB |
testcase_07 | AC | 59 ms
67,832 KB |
testcase_08 | AC | 51 ms
63,636 KB |
testcase_09 | AC | 44 ms
55,692 KB |
testcase_10 | AC | 43 ms
55,916 KB |
testcase_11 | AC | 77 ms
76,608 KB |
testcase_12 | AC | 618 ms
93,336 KB |
testcase_13 | AC | 933 ms
92,176 KB |
testcase_14 | AC | 44 ms
55,616 KB |
testcase_15 | AC | 933 ms
92,192 KB |
testcase_16 | AC | 501 ms
86,816 KB |
testcase_17 | AC | 779 ms
91,608 KB |
testcase_18 | AC | 695 ms
90,116 KB |
testcase_19 | AC | 734 ms
90,812 KB |
testcase_20 | AC | 966 ms
92,336 KB |
testcase_21 | AC | 962 ms
92,164 KB |
testcase_22 | AC | 972 ms
92,336 KB |
testcase_23 | AC | 165 ms
78,896 KB |
testcase_24 | AC | 338 ms
82,688 KB |
testcase_25 | AC | 685 ms
90,500 KB |
testcase_26 | AC | 584 ms
87,212 KB |
testcase_27 | AC | 506 ms
86,172 KB |
testcase_28 | AC | 821 ms
92,064 KB |
testcase_29 | AC | 432 ms
84,712 KB |
testcase_30 | AC | 245 ms
80,808 KB |
testcase_31 | AC | 220 ms
80,052 KB |
testcase_32 | AC | 551 ms
87,352 KB |
ソースコード
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, y = -x, -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 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 x, y in v[::-1]: count() last, k = 0, -1 for x, y in v: count() print(ans)