結果

問題 No.634 硬貨の枚数1
ユーザー 👑 obakyanobakyan
提出日時 2019-06-04 22:47:29
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 791 ms / 2,000 ms
コード長 710 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 133,844 KB
最終ジャッジ日時 2023-10-17 23:50:37
合計ジャッジ時間 24,016 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
133,844 KB
testcase_01 AC 67 ms
133,844 KB
testcase_02 AC 66 ms
133,844 KB
testcase_03 AC 67 ms
133,844 KB
testcase_04 AC 69 ms
133,844 KB
testcase_05 AC 68 ms
133,844 KB
testcase_06 AC 68 ms
133,844 KB
testcase_07 AC 71 ms
133,844 KB
testcase_08 AC 68 ms
133,844 KB
testcase_09 AC 68 ms
133,844 KB
testcase_10 AC 68 ms
133,844 KB
testcase_11 AC 70 ms
133,844 KB
testcase_12 AC 69 ms
133,844 KB
testcase_13 AC 69 ms
133,844 KB
testcase_14 AC 118 ms
133,844 KB
testcase_15 AC 685 ms
133,844 KB
testcase_16 AC 239 ms
133,844 KB
testcase_17 AC 374 ms
133,844 KB
testcase_18 AC 310 ms
133,844 KB
testcase_19 AC 68 ms
133,844 KB
testcase_20 AC 71 ms
133,844 KB
testcase_21 AC 479 ms
133,844 KB
testcase_22 AC 650 ms
133,844 KB
testcase_23 AC 227 ms
133,844 KB
testcase_24 AC 68 ms
133,844 KB
testcase_25 AC 68 ms
133,844 KB
testcase_26 AC 68 ms
133,844 KB
testcase_27 AC 68 ms
133,844 KB
testcase_28 AC 68 ms
133,844 KB
testcase_29 AC 68 ms
133,844 KB
testcase_30 AC 68 ms
133,844 KB
testcase_31 AC 69 ms
133,844 KB
testcase_32 AC 71 ms
133,844 KB
testcase_33 AC 67 ms
133,844 KB
testcase_34 AC 95 ms
133,844 KB
testcase_35 AC 233 ms
133,844 KB
testcase_36 AC 324 ms
133,844 KB
testcase_37 AC 263 ms
133,844 KB
testcase_38 AC 119 ms
133,844 KB
testcase_39 AC 419 ms
133,844 KB
testcase_40 AC 306 ms
133,844 KB
testcase_41 AC 397 ms
133,844 KB
testcase_42 AC 400 ms
133,844 KB
testcase_43 AC 222 ms
133,844 KB
testcase_44 AC 68 ms
133,844 KB
testcase_45 AC 75 ms
133,844 KB
testcase_46 AC 72 ms
133,844 KB
testcase_47 AC 88 ms
133,844 KB
testcase_48 AC 68 ms
133,844 KB
testcase_49 AC 67 ms
133,844 KB
testcase_50 AC 487 ms
133,844 KB
testcase_51 AC 115 ms
133,844 KB
testcase_52 AC 68 ms
133,844 KB
testcase_53 AC 68 ms
133,844 KB
testcase_54 AC 68 ms
133,844 KB
testcase_55 AC 773 ms
133,844 KB
testcase_56 AC 779 ms
133,844 KB
testcase_57 AC 749 ms
133,844 KB
testcase_58 AC 472 ms
133,844 KB
testcase_59 AC 472 ms
133,844 KB
testcase_60 AC 476 ms
133,844 KB
testcase_61 AC 484 ms
133,844 KB
testcase_62 AC 476 ms
133,844 KB
testcase_63 AC 767 ms
133,844 KB
testcase_64 AC 498 ms
133,844 KB
testcase_65 AC 490 ms
133,844 KB
testcase_66 AC 791 ms
133,844 KB
testcase_67 AC 501 ms
133,844 KB
testcase_68 AC 766 ms
133,844 KB
testcase_69 AC 756 ms
133,844 KB
testcase_70 AC 482 ms
133,844 KB
testcase_71 AC 477 ms
133,844 KB
testcase_72 AC 743 ms
133,844 KB
testcase_73 AC 477 ms
133,844 KB
testcase_74 AC 741 ms
133,844 KB
testcase_75 AC 724 ms
133,844 KB
testcase_76 AC 70 ms
133,844 KB
testcase_77 AC 68 ms
133,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl = math.floor
local n = io.read("*n")
local t = {}
local max = 4471
local v = {}
local inf = n + 1
for i = 1, max do v[i] = mfl(i * (i + 1) / 2) end
for i = 1, 10000000 do t[i] = inf end
local f = false
for i = 1, max do
  if n == v[i] then
    t[n] = 1
    f = true
    break
  elseif v[i] < n then
    t[v[i]] = 1
  end
end

local mmi = math.min
while not f do
  for i = n - 1, 1, -1 do
    if t[i] ~= inf then
      for i_v = 1, max do
        local dst = i + v[i_v]
        if dst == n then
          f = true
          t[n] = t[i] + 1
          break
        elseif dst < n then
          t[dst] = mmi(t[i] + 1, t[dst])
        end
      end
    end
    if f then break end
  end
end
print(t[n])
0