結果

問題 No.832 麻雀修行中
ユーザー 👑 obakyanobakyan
提出日時 2019-06-02 10:41:02
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,709 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 22:57:43
合計ジャッジ時間 1,987 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local str = io.read()
local t = {}
for i = 1, 9 do t[i] = 0 end
for i = 1, 13 do
  local a = tonumber(str:sub(i, i))
  t[a] = t[a] + 1
end

local function agaricore(tbl, tp)
  local tblcpy = {unpack(tbl)}
  for i = 1, 4 do
    local curmin = 9
    for j = 1, 9 do if 0 < tblcpy[j] then curmin = j break end end
    if tp[i] == 1 then
      if tblcpy[curmin] <= 2 then
        return false
      else
        tblcpy[curmin] = tblcpy[curmin] - 3
      end
    else
      if 8 <= curmin then
        return false
      elseif tblcpy[curmin] == 0 or tblcpy[curmin + 1] == 0 or tblcpy[curmin + 2] == 0 then
        return false
      else
        tblcpy[curmin] = tblcpy[curmin] - 1
        tblcpy[curmin + 1] = tblcpy[curmin + 1] - 1
        tblcpy[curmin + 2] = tblcpy[curmin + 2] - 1
      end
    end
  end
  return true
end

local function agari(tbl)
  -- chiitoi
  local chiitoi = 0
  for i = 1, 9 do
    if tbl[i] == 2 then chiitoi = chiitoi + 1 end
  end
  if chiitoi == 7 then return true end

  for i_atama = 1, 9 do
    if 2 <= tbl[i_atama] then
      tbl[i_atama] = tbl[i_atama] - 2
      -- print(unpack(tbl))
      for c = 0, 15 do
        local tp = {}
        local tc = c
        for i = 1, 4 do
          table.insert(tp, tc % 2)
          tc = math.floor(tc / 2)
        end
        local ret = agaricore(tbl, tp)
        if ret then
          tbl[i_atama] = tbl[i_atama] + 2
          return true
        end
      end
      tbl[i_atama] = tbl[i_atama] + 2
    end
  end
  return false
end

for i = 1, 9 do
  -- print("--" .. i .. "--")
  if t[i] <= 3 then
    t[i] = t[i] + 1
    -- print(unpack(t))
    -- print("--")
    if agari(t) then
      print(i)
    end
    t[i] = t[i] - 1
  end
end
0