結果

問題 No.832 麻雀修行中
ユーザー simansiman
提出日時 2022-11-02 13:38:46
言語 Ruby
(3.3.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 845 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 16,888 KB
最終ジャッジ日時 2023-09-24 03:16:38
合計ジャッジ時間 5,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,192 KB
testcase_01 AC 89 ms
15,400 KB
testcase_02 AC 87 ms
15,104 KB
testcase_03 AC 91 ms
16,456 KB
testcase_04 AC 89 ms
15,176 KB
testcase_05 AC 89 ms
15,320 KB
testcase_06 AC 87 ms
15,384 KB
testcase_07 AC 86 ms
15,188 KB
testcase_08 AC 87 ms
15,180 KB
testcase_09 AC 87 ms
15,164 KB
testcase_10 AC 86 ms
15,044 KB
testcase_11 AC 89 ms
16,500 KB
testcase_12 AC 87 ms
16,148 KB
testcase_13 AC 85 ms
15,104 KB
testcase_14 AC 89 ms
15,580 KB
testcase_15 AC 88 ms
15,324 KB
testcase_16 AC 86 ms
15,316 KB
testcase_17 AC 87 ms
15,152 KB
testcase_18 AC 87 ms
15,188 KB
testcase_19 AC 89 ms
15,308 KB
testcase_20 AC 86 ms
15,152 KB
testcase_21 AC 88 ms
15,428 KB
testcase_22 AC 82 ms
15,364 KB
testcase_23 AC 85 ms
15,208 KB
testcase_24 AC 87 ms
15,280 KB
testcase_25 AC 86 ms
15,212 KB
testcase_26 AC 86 ms
15,104 KB
testcase_27 AC 87 ms
15,084 KB
testcase_28 AC 86 ms
15,372 KB
testcase_29 AC 93 ms
16,888 KB
testcase_30 AC 87 ms
15,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

S = gets.chomp
L = S.chars.map(&:to_i)

def t(nums)
  nums.uniq.size == 7 && nums.each_slice(2).all? { |a, b| a == b }
end

def f(nums)
  h = nums.tally
  h.default = 0

  queue = []
  1.upto(9) do |n|
    g = h.dup

    if g[n] >= 2
      g[n] -= 2
      queue << g
    end
  end

  until queue.empty?
    g = queue.shift

    if (1..9).all? { |n| g[n] == 0 }
      return true
    end

    1.upto(9) do |n|
      if g[n] >= 3
        k = g.dup
        k[n] -= 3
        queue << k
      end
    end

    1.upto(7) do |n|
      if g[n] >= 1 && g[n + 1] >= 1 && g[n + 2] >= 1
        k = g.dup
        k[n] -= 1
        k[n + 1] -= 1
        k[n + 2] -= 1
        queue << k
      end
    end
  end

  false
end

1.upto(9) do |n|
  next if L.count(n) == 4

  nums = L.dup
  nums << n
  nums.sort!
  
  if t(nums) || f(nums)
    puts n
  end
end
0