結果

問題 No.458 異なる素数の和
ユーザー 👑 obakyanobakyan
提出日時 2019-04-13 22:06:56
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 720 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 14:35:32
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 95 ms
4,348 KB
testcase_02 AC 135 ms
4,348 KB
testcase_03 AC 23 ms
4,352 KB
testcase_04 AC 29 ms
4,348 KB
testcase_05 AC 277 ms
4,348 KB
testcase_06 AC 117 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 283 ms
4,352 KB
testcase_09 AC 8 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 342 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 14 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 116 ms
4,348 KB
testcase_28 AC 327 ms
4,352 KB
testcase_29 AC 4 ms
4,352 KB
testcase_30 AC 69 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

furui = {}
primes = {}
-- get primes
n = io.read("*n")
hn = math.ceil(n / 2)
for i = 2, hn do
  if(not furui[i]) then
    table.insert(primes, i)
    jmax = math.floor(hn / i)
    for j = 2, jmax do
      furui[j * i] = true
    end
  end
end
-- do DP
sumbox = {}
cursum = 0
sumbox[0] = 0
-- for i = 1, n do sumbox[i] = -1 end
for k, v in pairs(primes) do
  for i_sum = cursum, 0, -1 do
    if(sumbox[i_sum] ~= nil) then
      if(sumbox[i_sum + v] == nil) then
        sumbox[i_sum + v] = sumbox[i_sum] + 1
      else
        sumbox[i_sum + v] = math.max(sumbox[i_sum] + 1, sumbox[i_sum + v])
      end
    end
  end
  cursum = math.min(n, cursum + v)
end
if(sumbox[n] == nil) then print("-1") else print(sumbox[n]) end
0