結果

問題 No.1620 Substring Sum
ユーザー 👑 obakyanobakyan
提出日時 2021-07-22 22:08:06
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 6,884 KB
最終ジャッジ日時 2023-09-24 17:09:55
合計ジャッジ時間 1,543 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,312 KB
testcase_01 AC 8 ms
6,240 KB
testcase_02 AC 9 ms
6,312 KB
testcase_03 AC 9 ms
6,312 KB
testcase_04 AC 17 ms
6,616 KB
testcase_05 AC 16 ms
6,776 KB
testcase_06 AC 16 ms
6,764 KB
testcase_07 AC 17 ms
6,604 KB
testcase_08 AC 17 ms
6,692 KB
testcase_09 AC 16 ms
6,600 KB
testcase_10 AC 15 ms
6,792 KB
testcase_11 AC 16 ms
6,648 KB
testcase_12 AC 10 ms
6,228 KB
testcase_13 AC 16 ms
6,640 KB
testcase_14 AC 17 ms
6,760 KB
testcase_15 AC 15 ms
6,628 KB
testcase_16 AC 13 ms
6,440 KB
testcase_17 AC 14 ms
6,672 KB
testcase_18 AC 8 ms
6,372 KB
testcase_19 AC 8 ms
6,256 KB
testcase_20 AC 16 ms
6,608 KB
testcase_21 AC 16 ms
6,884 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 p11 = {1}
local p2 = {1}
for i = 2, 200010 do
  p11[i] = (p11[i - 1] * 11) % mod
  p2[i] = (p2[i - 1] * 2) % mod
end

local s = io.read()
local n = #s
local ret = 0
for i = 1, n do
  local t = s:byte(i) - 48
  local right = n - i
  local left = i - 1
  local v = bmul(t, bmul(p11[right + 1], p2[left + 1]))
  ret = badd(ret, v)
end
print(ret)
0