結果

問題 No.10 +か×か
ユーザー 👑 obakyanobakyan
提出日時 2020-04-26 14:33:31
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 666 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 53,584 KB
最終ジャッジ日時 2023-08-21 06:29:02
合計ジャッジ時間 1,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,504 KB
testcase_03 AC 73 ms
53,568 KB
testcase_04 AC 41 ms
27,880 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 73 ms
53,584 KB
testcase_07 AC 42 ms
27,972 KB
testcase_08 AC 18 ms
15,404 KB
testcase_09 AC 28 ms
23,716 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local n = io.read("*n")
local r = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local t = {}
for i = 1, n do
  t[i] = {}
  for j = 1, r do
    t[i][j] = false
  end
end
t[n][r] = true
for i = n, 2, -1 do
  for j = a[i] + 1, r do
    if t[i][j] then
      t[i - 1][j - a[i]] = true
    end
  end
  local lim = mfl(r / a[i])
  for j = 1, lim do
    if t[i][j * a[i]] then
      t[i - 1][j] = true
    end
  end
end
local cur = a[1]
for i = 1, n - 1 do
  if t[i + 1][cur + a[i + 1]] then
    io.write("+")
    cur = cur + a[i + 1]
  else
    io.write("*")
    cur = cur * a[i + 1]
  end
end
io.write("\n")
0