結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー 👑 obakyanobakyan
提出日時 2022-02-01 23:29:35
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 795 ms / 2,000 ms
コード長 1,638 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 5,368 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-02 02:37:16
合計ジャッジ時間 10,373 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 19 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 133 ms
4,376 KB
testcase_09 AC 131 ms
4,380 KB
testcase_10 AC 133 ms
4,376 KB
testcase_11 AC 107 ms
4,376 KB
testcase_12 AC 135 ms
4,380 KB
testcase_13 AC 135 ms
4,376 KB
testcase_14 AC 791 ms
4,376 KB
testcase_15 AC 779 ms
4,380 KB
testcase_16 AC 795 ms
4,376 KB
testcase_17 AC 789 ms
4,380 KB
testcase_18 AC 771 ms
4,500 KB
testcase_19 AC 772 ms
4,380 KB
testcase_20 AC 558 ms
4,376 KB
testcase_21 AC 619 ms
4,380 KB
testcase_22 AC 109 ms
4,376 KB
testcase_23 AC 689 ms
4,376 KB
testcase_24 AC 89 ms
4,384 KB
testcase_25 AC 199 ms
4,380 KB
testcase_26 AC 66 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 103 ms
4,376 KB
testcase_31 AC 100 ms
4,376 KB
testcase_32 AC 101 ms
4,376 KB
testcase_33 AC 102 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 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 n, m, t = io.read():match("(%d+) (%d+) (%d+)")
n = tonumber(n)
m = tonumber(m)
t = lltonumber(t)
local mat = {}
for i = 1, n do
  mat[i] = {}
  for j = 1, n do mat[i][j] = 0 end
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  a, b = a + 1, b + 1
  mat[a][b], mat[b][a] = 1, 1
end
local vec = {1}
for i = 2, n do vec[i] = 0 end
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 = badd(v, bmul(mat[i][k], mat[k][j]))
      end
      tmpmat[i][j] = v
    end
  end
  for i = 1, n do for j = 1, n do
    mat[i][j] = tmpmat[i][j]
  end end
end

local function vecmat()
  for i = 1, n do
    local v = 0
    for k = 1, n do
      v = badd(v, bmul(vec[k], mat[k][i]))
    end
    tmpvec[i] = v
  end
  for i = 1, n do
    vec[i] = tmpvec[i]
  end
end
local function matvec()
  for i = 1, n do
    local v = 0
    for k = 1, n do
      v = badd(v, bmul(mat[i][k], vec[k]))
    end
    tmpvec[i] = v
  end
  for i = 1, n do
    vec[i] = tmpvec[i]
  end
end

while 0LL < t do
  if t % 2LL == 1LL then
    matvec()
  end
  matmat()
  t = t / 2LL
end
print(vec[1])
0