結果

問題 No.2197 Same Dish
ユーザー 👑 obakyanobakyan
提出日時 2023-02-08 23:07:14
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 6,572 KB
最終ジャッジ日時 2023-09-20 12:40:13
合計ジャッジ時間 2,617 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,412 KB
testcase_01 AC 7 ms
6,424 KB
testcase_02 AC 6 ms
6,340 KB
testcase_03 AC 6 ms
6,464 KB
testcase_04 AC 6 ms
6,428 KB
testcase_05 AC 6 ms
6,424 KB
testcase_06 AC 5 ms
6,452 KB
testcase_07 AC 6 ms
6,572 KB
testcase_08 AC 6 ms
6,532 KB
testcase_09 AC 6 ms
6,368 KB
testcase_10 AC 6 ms
6,488 KB
testcase_11 AC 5 ms
6,440 KB
testcase_12 AC 6 ms
6,400 KB
testcase_13 AC 12 ms
6,508 KB
testcase_14 AC 48 ms
6,388 KB
testcase_15 AC 54 ms
6,408 KB
testcase_16 AC 36 ms
6,360 KB
testcase_17 AC 32 ms
6,344 KB
testcase_18 AC 51 ms
6,360 KB
testcase_19 AC 50 ms
6,548 KB
testcase_20 AC 51 ms
6,488 KB
testcase_21 AC 46 ms
6,348 KB
testcase_22 AC 54 ms
6,532 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 function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end
local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local n, k = io.read("*n", "*n")
local add, rm = {}, {}
local lim = 200010
for i = 1, lim do
  add[i], rm[i] = 0, 0
end
for i = 1, n do
  local l, r = io.read("*n", "*n")
  add[l] = add[l] + 1
  rm[r] = rm[r] + 1
end
local a = 1
local cur = 0
for i = 1, lim do
  cur = cur - rm[i]
  for j = 1, add[i] do
    local rem = k - cur
    if rem <= 0 then a = 0 break end
    a = bmul(a, rem % mod)
    cur = cur + 1
  end
  if a == 0 then break end
end
local tot = modpow(k % mod, n)
local ans = bsub(tot, a)
print(ans)
0