結果

問題 No.1084 積の積
ユーザー 👑 obakyanobakyan
提出日時 2021-05-04 23:30:46
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,628 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 6,512 KB
最終ジャッジ日時 2023-10-01 00:56:38
合計ジャッジ時間 3,114 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 124 ms
6,356 KB
testcase_05 AC 15 ms
4,380 KB
testcase_06 AC 124 ms
6,464 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 22 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 16 ms
4,416 KB
testcase_13 AC 31 ms
6,460 KB
testcase_14 AC 12 ms
4,380 KB
testcase_15 AC 12 ms
4,380 KB
testcase_16 AC 35 ms
6,348 KB
testcase_17 AC 16 ms
4,564 KB
testcase_18 AC 24 ms
4,568 KB
testcase_19 AC 32 ms
6,512 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 20 ms
4,504 KB
testcase_24 AC 18 ms
4,604 KB
testcase_25 AC 32 ms
6,388 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local mod = 1000000007
local function badd(a, b) return (a + b) % mod end
local function bsub(a, b) return (a + mod - b) % mod end
local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end
local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local n = io.read("*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
for i = 1, n do if a[i] == 0 then print(0) os.exit() end end
local lim = 1000000007 - 7

local right = 0
local cur = 1
local rpos = {}
for i = 1, n do
  if 1 < i then
    cur = mfl(cur / a[i - 1])
  end
  while true do
    if right == n then break end
    -- cur * a[right + 1] < lim
    if a[right + 1] < mfl(lim / cur) then
      right = right + 1
      cur = cur * a[right]
    else
      break
    end
  end
  rpos[i] = right
end

local cnt = {}
local velocity = {}
for i = 1, n do
  cnt[i] = 0
  velocity[i] = 0
end
for i = 1, n do
  local r = rpos[i]
  cnt[i] = cnt[i] + r - i + 1
  velocity[i] = velocity[i] - 1
  if r < n then
    velocity[r + 1] = velocity[r + 1] + 1
  end
end
for i = 2, n do
  velocity[i] = velocity[i] + velocity[i - 1]
end

local ret = 1
for i = 1, n do
  if 1 < i then cnt[i] = cnt[i] + cnt[i - 1] end
  ret = bmul(ret, modpow(a[i], cnt[i]))
  cnt[i] = cnt[i] + velocity[i]
end
print(ret)
0