結果

問題 No.832 麻雀修行中
ユーザー wipexwipex
提出日時 2019-09-28 18:35:19
言語 Ruby
(3.3.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 51 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-14 06:19:26
合計ジャッジ時間 4,156 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
12,160 KB
testcase_01 AC 97 ms
12,288 KB
testcase_02 AC 88 ms
12,160 KB
testcase_03 AC 88 ms
12,160 KB
testcase_04 AC 87 ms
12,288 KB
testcase_05 AC 87 ms
12,416 KB
testcase_06 AC 86 ms
12,288 KB
testcase_07 AC 89 ms
12,160 KB
testcase_08 AC 88 ms
12,160 KB
testcase_09 AC 88 ms
12,160 KB
testcase_10 AC 88 ms
12,160 KB
testcase_11 AC 88 ms
12,160 KB
testcase_12 AC 88 ms
12,160 KB
testcase_13 AC 88 ms
12,160 KB
testcase_14 AC 87 ms
12,288 KB
testcase_15 AC 87 ms
12,160 KB
testcase_16 AC 87 ms
12,288 KB
testcase_17 AC 88 ms
12,160 KB
testcase_18 AC 87 ms
12,288 KB
testcase_19 AC 87 ms
12,160 KB
testcase_20 AC 86 ms
12,160 KB
testcase_21 AC 87 ms
12,288 KB
testcase_22 AC 88 ms
12,160 KB
testcase_23 AC 86 ms
12,160 KB
testcase_24 AC 87 ms
12,288 KB
testcase_25 AC 87 ms
12,160 KB
testcase_26 AC 88 ms
12,160 KB
testcase_27 AC 88 ms
12,288 KB
testcase_28 AC 87 ms
12,160 KB
testcase_29 AC 86 ms
12,160 KB
testcase_30 AC 90 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:15: warning: `*' interpreted as argument prefix
Syntax OK

ソースコード

diff #

s = gets.chomp.split("").map(&:to_i).sort

def f(n,g)
  return g.all?{|k, v| v == 0 } if n > 9
  if g[n] == 0
    f(n+1,g)
  else
    (if n <= 7 && g[n] > 0 && g[n+1] > 0 && g[n+2] > 0
     g[n] -= 1;g[n+1] -= 1;g[n+2] -= 1
     f(n,g).tap{ g[n] += 1;g[n+1] += 1;g[n+2] += 1 } end)||
      (if g[n] >= 3;g[n] -= 3;f(n,g).tap{ g[n] += 3 } end )
  end
end

p *(1..9).select{|n|
  a =s+[n]
  h = a.group_by(&:itself).map{|k,v|[k,v.size]}.to_h
  h.default = 0
  next if (1..9).any?{|x| h[x] >4}
  if h.all?{|k,v| v ==2}
    true
  else
    (1..9).any?{|j|
      next if h[j] < 2
      g = h.dup; g[j] -= 2
      f(1,g)
    }
  end
}
0