結果

問題 No.1569 Nixoracci's Number
ユーザー 👑 obakyanobakyan
提出日時 2021-08-10 20:01:32
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,238 ms / 2,000 ms
コード長 1,793 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 05:18:55
合計ジャッジ時間 9,141 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 3 ms
4,372 KB
testcase_04 AC 839 ms
4,372 KB
testcase_05 AC 58 ms
4,372 KB
testcase_06 AC 1,238 ms
4,372 KB
testcase_07 AC 4 ms
4,372 KB
testcase_08 AC 114 ms
4,372 KB
testcase_09 AC 12 ms
4,372 KB
testcase_10 AC 61 ms
4,372 KB
testcase_11 AC 180 ms
4,372 KB
testcase_12 AC 449 ms
4,372 KB
testcase_13 AC 616 ms
4,372 KB
testcase_14 AC 86 ms
4,372 KB
testcase_15 AC 824 ms
4,372 KB
testcase_16 AC 135 ms
4,372 KB
testcase_17 AC 71 ms
4,372 KB
testcase_18 AC 199 ms
4,372 KB
testcase_19 AC 64 ms
4,372 KB
testcase_20 AC 1,059 ms
4,372 KB
testcase_21 AC 475 ms
4,372 KB
testcase_22 AC 121 ms
4,372 KB
testcase_23 AC 1,216 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil

local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end

local n, k = io.read():match("(%d+) (%d+)")
n = tonumber(n)
local strk = k
k = lltonumber(k)
local str = io.read()
local dlim = 60

local mat = {}
for i = 1, n - 1 do
  mat[i] = {}
  for j = 1, n do
    mat[i][j] = 1 + i == j and 1 or 0
  end
end
mat[n] = {}
for j = 1, n do mat[n][j] = 1 end
local vec = {}
for i = 1, dlim do vec[i] = {} end
local a = {}
do
  local i = 0
  for w in str:gmatch("%d+") do
    i = i + 1
    w = lltonumber(w)
    a[i] = w
    assert(w <= 1000000000000000000LL)
    for j = 1, dlim do
      vec[j][i] = w % 2LL == 0 and 0 or 1
      w = w / 2LL
    end
  end
end
if #strk <= 3 then
  local tk = tonumber(strk)
  if tk <= n then
    print(a[tk])
    os.exit()
  end
end
k = k - n

local tmpmat = {}
for i = 1, n do
  tmpmat[i] = {}
end
local tmpvec = {}

local function matmat()
  for i = 1, n do
    for j = 1, n do
      local v = 0
      for k = 1, n do
        v = v + mat[i][k] * mat[k][j]
      end
      tmpmat[i][j] = v % 2
    end
  end
  for i = 1, n do for j = 1, n do
    mat[i][j] = tmpmat[i][j]
  end end
end
local function matvec()
  for d = 1, dlim do
    local vd = vec[d]
    for i = 1, n do
      local v = 0
      for k = 1, n do
        v = v + mat[i][k] * vec[d][k]
      end
      tmpvec[i] = v % 2
    end
    for i = 1, n do
      vec[d][i] = tmpvec[i]
    end
  end
end
while 0LL < k do
  if k % 2LL == 1LL then
    matvec()
  end
  matmat()
  k = k / 2LL
end
local ret = 0LL
local mul = 1LL
for i = 1, dlim do
  if vec[i][n] == 1 then
    ret = ret + mul
  end
  mul = mul + mul
end
ret = tostring(ret):gsub("LL", "")
print(ret)
-- print(os.clock())
0