結果
問題 | No.1709 Indistinguishable by MEX |
ユーザー |
👑 |
提出日時 | 2022-04-24 21:04:04 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 910 bytes |
コンパイル時間 | 421 ms |
コンパイル使用メモリ | 7,328 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-06-26 07:57:43 |
合計ジャッジ時間 | 3,198 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
local mod = 998244353local mfl = math.floorlocal function bmul(x, y)local x0, y0 = x % 31596, y % 31596local x1, y1 = mfl(x / 31596), mfl(y / 31596)return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % modendlocal n = io.read("*n")local p = {}local pinv = {}for i = 1, n do pinv[i] = 0 endfor i = 1, n dop[i] = io.read("*n") + 1pinv[p[i]] = iendif n == 1 then print(1) os.exit() endlocal internal_use = 0local left = pinv[1]local right = leftdolocal pos = pinv[2]if pos < left then left = pos else right = pos endendlocal ret = 1for i = 3, n dolocal pos = pinv[i]if left < pos and pos < right thenlocal remain = right - left - 1 - internal_useret = bmul(ret, remain)internal_use = internal_use + 1elseif pos < left thenleft = poselseright = posendinternal_use = internal_use + 1endendprint(ret)