結果

問題 No.2008 Super Worker
ユーザー qibqib
提出日時 2022-10-15 18:27:38
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 461 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 163,744 KB
最終ジャッジ日時 2024-06-26 20:12:12
合計ジャッジ時間 29,949 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

from fractions import Fraction

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cur = 1
inv = {}
for i in range(n):
  cur = (cur * b[i]) % MOD
  if not b[i] in inv:
    inv[b[i]] = pow(b[i], MOD - 2, MOD)

order = [i for i in range(n)]
order.sort(key=lambda i: Fraction(b[i] - 1, a[i]))

ans = 0
for i in order:
  ans = (ans + cur * a[i] * inv[b[i]]) % MOD
  cur = (cur * inv[b[i]]) % MOD

print(ans)
0