結果

問題 No.1885 Flat Permutation
ユーザー 👑 obakyan
提出日時 2022-04-19 09:44:15
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 540 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 6,820 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-31 14:10:02
合計ジャッジ時間 1,973 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

local mod = 998244353
local n, x, y = io.read("*n", "*n", "*n")
if y < x then x, y = y, x end
if n == 2 then print(1) os.exit() end

local function walk(a)
  if a == 0 then return 0 end
  local t = {1}
  for i = 2, a do
    if 3 < i then
      t[i] = (t[i - 1] + t[i - 3]) % mod
    else
      t[i] = t[i - 1]
    end
  end
  return t[a]
end

local ret = 1
if x == 1 then
  if y == n then
    ret = walk(n)
  else
    ret = walk(y - 1)
  end
else
  if y == n then
    ret = walk(n - x)
  else
    ret = walk(y - x - 1)
  end
end
print(ret)
0