結果

問題 No.2111 Sum of Diff
ユーザー 👑 obakyanobakyan
提出日時 2022-10-29 01:09:36
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 6,492 KB
最終ジャッジ日時 2023-09-20 08:17:25
合計ジャッジ時間 2,061 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 53 ms
6,356 KB
testcase_03 AC 38 ms
6,356 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 54 ms
6,492 KB
testcase_06 AC 53 ms
6,308 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 20 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 27 ms
4,380 KB
testcase_12 AC 26 ms
4,380 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 45 ms
6,368 KB
testcase_15 AC 52 ms
6,356 KB
testcase_16 AC 24 ms
4,376 KB
testcase_17 AC 54 ms
6,416 KB
testcase_18 AC 18 ms
4,380 KB
testcase_19 AC 42 ms
6,356 KB
testcase_20 AC 54 ms
6,464 KB
testcase_21 AC 2 ms
4,380 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 badd(x, y) return (x + y) % mod end
local n = io.read("*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local pw = {1}
for i = 2, n do
  pw[i] = badd(pw[i - 1], pw[i - 1])
end

local z = 0
local ans = 0
for i = n - 1, 1, -1 do
  z = badd(z, pw[i])
  ans = badd(ans, bmul(z, badd(a[i], mod - a[n + 1 - i])))
end
print(ans)
0