結果

問題 No.1709 Indistinguishable by MEX
ユーザー 👑 obakyanobakyan
提出日時 2022-04-24 21:04:04
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 910 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2023-09-08 14:53:06
合計ジャッジ時間 3,646 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 47 ms
6,196 KB
testcase_09 AC 40 ms
6,200 KB
testcase_10 AC 35 ms
4,536 KB
testcase_11 AC 28 ms
4,384 KB
testcase_12 AC 28 ms
4,424 KB
testcase_13 AC 42 ms
6,216 KB
testcase_14 AC 39 ms
6,376 KB
testcase_15 AC 41 ms
6,200 KB
testcase_16 AC 52 ms
6,200 KB
testcase_17 AC 48 ms
6,212 KB
testcase_18 AC 56 ms
6,272 KB
testcase_19 AC 56 ms
6,240 KB
testcase_20 AC 56 ms
6,400 KB
testcase_21 AC 54 ms
6,348 KB
testcase_22 AC 54 ms
6,400 KB
testcase_23 AC 48 ms
6,272 KB
testcase_24 AC 48 ms
6,248 KB
testcase_25 AC 47 ms
6,372 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 25 ms
4,460 KB
testcase_28 AC 24 ms
4,384 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 n = io.read("*n")
local p = {}
local pinv = {}
for i = 1, n do pinv[i] = 0 end
for i = 1, n do
  p[i] = io.read("*n") + 1
  pinv[p[i]] = i
end
if n == 1 then print(1) os.exit() end
local internal_use = 0
local left = pinv[1]
local right = left
do
  local pos = pinv[2]
  if pos < left then left = pos else right = pos end
end
local ret = 1
for i = 3, n do
  local pos = pinv[i]
  if left < pos and pos < right then
    local remain = right - left - 1 - internal_use
    ret = bmul(ret, remain)
    internal_use = internal_use + 1
  else
    if pos < left then
      left = pos
    else
      right = pos
    end
    internal_use = internal_use + 1
  end
end
print(ret)
0