結果
問題 | No.334 門松ゲーム |
ユーザー |
|
提出日時 | 2016-01-16 21:55:41 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 139 ms / 2,000 ms |
コード長 | 1,147 bytes |
コンパイル時間 | 70 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 13,056 KB |
最終ジャッジ日時 | 2024-09-19 20:15:20 |
合計ジャッジ時間 | 2,178 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
コンパイルメッセージ
Main.rb:47: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:56: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
def kadomatsu original,index tmp = [] 3.times{|i| tmp.push(original[index[i]]) } if tmp.uniq != tmp || tmp.minmax == [tmp[0],tmp[2]].sort return false else return true end end def solution kado,rest,count tmp = rest.combination(3).to_a.select{|a|kadomatsu(kado,a)} flag = count % 2 if tmp.empty? if flag == 0 return false else return true end else tmp.each{|w| if flag == 0 if solution(kado,rest - w,count + 1) return true end else unless solution(kado,rest - w,count + 1) return false end end } if flag == 0 return false else return true end end end n = gets.to_i k = gets.split.map(&:to_i) range = [*0..n-1] kado = range.combination(3).to_a.select{|a|kadomatsu(k,a)} if kado.empty? puts -1 exit end kado.each{|v| if solution(k,range - v,1) puts v.join(' ') exit end } puts -1