結果

問題 No.1097 Remainder Operation
ユーザー 👑 obakyanobakyan
提出日時 2021-05-24 09:33:21
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,151 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 314,828 KB
最終ジャッジ日時 2024-04-20 19:23:10
合計ジャッジ時間 13,556 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 76 ms
32,640 KB
testcase_08 AC 81 ms
34,688 KB
testcase_09 AC 76 ms
34,816 KB
testcase_10 AC 73 ms
32,640 KB
testcase_11 AC 72 ms
32,640 KB
testcase_12 AC 1,039 ms
314,828 KB
testcase_13 AC 974 ms
284,976 KB
testcase_14 AC 982 ms
284,940 KB
testcase_15 AC 989 ms
284,988 KB
testcase_16 AC 1,055 ms
314,684 KB
testcase_17 AC 649 ms
271,232 KB
testcase_18 AC 678 ms
271,104 KB
testcase_19 AC 956 ms
314,684 KB
testcase_20 AC 960 ms
314,672 KB
testcase_21 AC 1,011 ms
283,416 KB
testcase_22 AC 1,151 ms
313,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local n = io.read("*n")
local a = {}
for i = 0, n - 1 do
  a[i] = io.read("*n")
end
local up = {{}}
local t = {{}}
for i = 0, n - 1 do
  local dst = (i + a[i]) % n
  t[1][i] = dst
  up[1][i] = 1LL * mfl((i + a[i]) / n)
end
-- print(table.concat(t[1], " "))
for i = 2, 45 do
  t[i] = {}
  up[i] = {}
  for j = 0, n - 1 do
    local z = t[i - 1][j]
    t[i][j] = t[i - 1][z]
    up[i][j] = up[i - 1][j] + up[i - 1][z]
  end
  -- print(table.concat(t[i], " "))
end
local q = io.read("*n")
for iq = 1, q do
  local k = io.read("*n")
  local cur = 0
  local u = 0LL
  for i = 1, 45 do
    if k == 0 then break end
    if k % 2 == 1 then
      u = u + up[i][cur]
      cur = t[i][cur]
    end
    k = mfl(k / 2)
  end
  local z = u * n + cur
  local zs = tostring(z):gsub("LL", "")
  print(zs)
end
0