結果

問題 No.1325 Subsequence Score
ユーザー 👑 obakyanobakyan
提出日時 2021-05-25 23:36:07
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 5,504 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2024-04-22 15:14:50
合計ジャッジ時間 5,162 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
10,880 KB
testcase_01 AC 21 ms
11,008 KB
testcase_02 AC 21 ms
11,008 KB
testcase_03 AC 22 ms
10,752 KB
testcase_04 AC 22 ms
10,752 KB
testcase_05 AC 22 ms
10,880 KB
testcase_06 AC 22 ms
10,880 KB
testcase_07 AC 22 ms
10,880 KB
testcase_08 AC 22 ms
10,880 KB
testcase_09 AC 21 ms
10,880 KB
testcase_10 AC 22 ms
10,880 KB
testcase_11 AC 21 ms
10,880 KB
testcase_12 AC 22 ms
10,880 KB
testcase_13 AC 187 ms
14,976 KB
testcase_14 AC 69 ms
12,928 KB
testcase_15 AC 161 ms
14,976 KB
testcase_16 AC 170 ms
14,976 KB
testcase_17 AC 85 ms
12,928 KB
testcase_18 AC 59 ms
11,904 KB
testcase_19 AC 178 ms
14,976 KB
testcase_20 AC 42 ms
11,392 KB
testcase_21 AC 77 ms
12,928 KB
testcase_22 AC 90 ms
12,928 KB
testcase_23 AC 181 ms
14,848 KB
testcase_24 AC 179 ms
14,848 KB
testcase_25 AC 189 ms
14,848 KB
testcase_26 AC 187 ms
14,976 KB
testcase_27 AC 180 ms
14,848 KB
testcase_28 AC 22 ms
10,880 KB
testcase_29 AC 21 ms
10,752 KB
testcase_30 AC 21 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mod = 998244353
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31596, y % 31596
  local x1, y1 = mfl(x / 31596), mfl(y / 31596)
  return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod
end
local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end
local p2 = {2}
for i = 2, 1000010 do
  p2[i] = badd(p2[i - 1], p2[i - 1])
end
local function getp2(i)
  if i == 0 then return 1 else return p2[i] end
end

local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n") % mod
end
local ret = 0
for i = n, 1, -1 do
  if 1 < i then
    local v = badd(getp2(i - 1), bmul(i - 1, getp2(i - 2)))
    v = bmul(v, getp2(n - i))
    ret = badd(ret, bmul(a[i], v))
  else
    ret = badd(ret, bmul(a[i], getp2(n - 1)))
  end
end
print(ret)
0