結果

問題 No.1443 Andd
ユーザー 👑 obakyanobakyan
提出日時 2021-07-24 17:52:30
言語 Lua
(LuaJit 2.1.1696795921)
結果
MLE  
実行時間 -
コード長 942 bytes
コンパイル時間 51 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 587,960 KB
最終ジャッジ日時 2023-09-27 06:04:14
合計ジャッジ時間 8,046 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 26 ms
19,728 KB
testcase_04 AC 36 ms
24,896 KB
testcase_05 AC 26 ms
20,748 KB
testcase_06 AC 26 ms
19,328 KB
testcase_07 AC 37 ms
24,424 KB
testcase_08 AC 36 ms
22,796 KB
testcase_09 AC 6 ms
5,136 KB
testcase_10 AC 43 ms
27,288 KB
testcase_11 AC 41 ms
25,628 KB
testcase_12 AC 39 ms
25,296 KB
testcase_13 AC 208 ms
149,664 KB
testcase_14 AC 205 ms
149,676 KB
testcase_15 AC 206 ms
149,888 KB
testcase_16 AC 220 ms
149,604 KB
testcase_17 AC 203 ms
149,512 KB
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

local band = bit.band
local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local asum = {a[1]}
for i = 2, n do
  asum[i] = asum[i - 1] + a[i]
end
local all = {}
for i = 1, 1024 * n do
  all[i] = false
end
local dp1, dp2 = {}, {}
dp1[1] = {true}
dp2[1] = {false}
for i = 2, 1024 do
  dp1[1][i] = false
  dp2[1][i] = false
end
for i = 1, n do
  dp1[i + 1] = {}
  dp2[i + 1] = {}
  for j = 1, 1024 do
    dp1[i + 1][j] = false
    dp2[i + 1][j] = false
  end
  local ai = a[i]
  for j = 1, 1024 do
    if dp1[i][j] or dp2[i][j] then
      local dst1 = band(j - 1, ai) + 1
      local dst2 = ((j - 1 + ai) % 1024) + 1
      dp1[i + 1][dst1] = true
      dp2[i + 1][dst2] = true
    end
  end
end
local ret = 1
all[asum[n] + 1] = true
for i = 1, n do
  for j = 1, 1024 do
    local v = j + asum[n] - asum[i]
    if dp1[i + 1][j] and not all[v] then
      ret = ret + 1
      all[v] = true
    end
  end
  print(ret)
end
0