結果
問題 | No.1084 積の積 |
ユーザー | 👑 obakyan |
提出日時 | 2021-05-05 00:00:19 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 127 ms / 2,000 ms |
コード長 | 1,656 bytes |
コンパイル時間 | 93 ms |
コンパイル使用メモリ | 5,336 KB |
実行使用メモリ | 6,744 KB |
最終ジャッジ日時 | 2023-10-01 01:22:30 |
合計ジャッジ時間 | 2,633 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 126 ms
6,468 KB |
testcase_05 | AC | 15 ms
4,380 KB |
testcase_06 | AC | 127 ms
6,472 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 22 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 3 ms
4,380 KB |
testcase_12 | AC | 17 ms
4,580 KB |
testcase_13 | AC | 34 ms
6,348 KB |
testcase_14 | AC | 13 ms
4,380 KB |
testcase_15 | AC | 13 ms
4,380 KB |
testcase_16 | AC | 38 ms
6,264 KB |
testcase_17 | AC | 16 ms
4,440 KB |
testcase_18 | AC | 25 ms
4,520 KB |
testcase_19 | AC | 34 ms
6,360 KB |
testcase_20 | AC | 9 ms
4,376 KB |
testcase_21 | AC | 13 ms
4,376 KB |
testcase_22 | AC | 10 ms
4,380 KB |
testcase_23 | AC | 21 ms
4,568 KB |
testcase_24 | AC | 19 ms
4,624 KB |
testcase_25 | AC | 34 ms
6,416 KB |
testcase_26 | AC | 38 ms
6,560 KB |
testcase_27 | AC | 38 ms
6,300 KB |
testcase_28 | AC | 38 ms
6,360 KB |
testcase_29 | AC | 38 ms
6,392 KB |
testcase_30 | AC | 38 ms
6,500 KB |
testcase_31 | AC | 38 ms
6,744 KB |
ソースコード
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 n = io.read("*n") local a = {} for i = 1, n do a[i] = io.read("*n") end local lim = 1000000007 - 7 a[n + 1] = lim + 1 for i = 1, n do if a[i] == 0 then print(0) os.exit() end end 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 cur * a[right + 1] < lim then local z = mfl(lim / a[right + 1]) local f = cur < z if lim % a[right + 1] ~= 0 then f = cur <= z end if f 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)