結果

問題 No.1463 Hungry Kanten
ユーザー 👑 obakyanobakyan
提出日時 2021-05-05 15:12:22
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 474 ms / 2,000 ms
コード長 1,657 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 57,488 KB
最終ジャッジ日時 2023-10-11 09:53:21
合計ジャッジ時間 2,925 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 15 ms
4,348 KB
testcase_03 AC 127 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 474 ms
57,488 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 5 ms
4,356 KB
testcase_16 AC 16 ms
4,644 KB
testcase_17 AC 41 ms
7,560 KB
testcase_18 AC 35 ms
4,352 KB
testcase_19 AC 197 ms
29,332 KB
testcase_20 AC 325 ms
37,516 KB
testcase_21 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local bls, brs = bit.lshift, bit.rshift
local mfl = math.floor

local mod1, mod2, mod3 = 1000000007, 1000000009, 998244353

local function bmul(x, y, mod)
  local z1, z2 = 31623, 14122
  if mod == 1000000009 then
    z2 = 14120
  elseif mod == 998244353 then
    z1, z2 = 31596, 62863
  end
  local x1, y1 = mfl(x / z1), mfl(y / z1)
  local x0, y0 = x - x1 * z1, y - y1 * z1
  return (x1 * y1 * z2 + (x1 * y0 + x0 * y1) * z1 + x0 * y0) % mod
end

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

local function modinv(src, mod)
  return modpow(src, mod - 2, mod)
end

local n, k = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local t = {}
local g = {}

local tot = bls(1, n)
for i = 0, tot - 1 do
  local sum = 0
  local rawmul = 1
  local m1, m2, m3 = 1, 1, 1
  local ti = i
  local c = 0
  for j = 1, n do
    if ti % 2 == 1 then
      c = c + 1
      sum = sum + a[j]
      rawmul = rawmul * a[j]
      m1, m2, m3 = bmul(m1, a[j], mod1), bmul(m2, a[j], mod2), bmul(m3, a[j], mod3)
    end
    ti = brs(ti, 1)
  end
  if k <= c then
    t[sum] = true
    if rawmul < 20 * 1000 then
      t[rawmul] = true
    else
      if not g[m1] then g[m1] = {} end
      if not g[m1][m2] then g[m1][m2] = {} end
      g[m1][m2][m3] = true
    end
  end
end
local ret = 0
for _k, _v in pairs(t) do
  ret = ret + 1
end
for _m1, t1 in pairs(g) do
  for _m2, t2 in pairs(t1) do
    for _m3, _t3 in pairs(t2) do
      ret = ret + 1
    end
  end
end
print(ret)
0