結果
| 問題 | 
                            No.334 門松ゲーム
                             | 
                    
| コンテスト | |
| ユーザー | 
                             siman
                         | 
                    
| 提出日時 | 2021-03-24 03:39:59 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 165 ms / 2,000 ms | 
| コード長 | 671 bytes | 
| コンパイル時間 | 52 ms | 
| コンパイル使用メモリ | 7,424 KB | 
| 実行使用メモリ | 12,416 KB | 
| 最終ジャッジ日時 | 2024-11-26 11:23:08 | 
| 合計ジャッジ時間 | 2,599 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 13 | 
コンパイルメッセージ
Main.rb:42: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
N = gets.to_i
K = gets.split.map(&:to_i)
def dfs(nums, turn = 0)
  l = nums.size
  win = turn.odd?
  [*0...l].combination(3) do |a, b, c|
    next if nums[a] == nums[b]
    next if nums[a] == nums[c]
    next if nums[b] == nums[c]
    next if nums[a] < nums[b] && nums[b] < nums[c]
    next if nums[a] > nums[b] && nums[b] > nums[c]
    arr = []
    l.times do |i|
      next if i == a
      next if i == b
      next if i == c
      arr << nums[i]
    end
    if turn.even?
      win |= dfs(arr, turn + 1)
    else
      win &= dfs(arr, turn + 1)
    end
    if turn == 0 && win
      puts [a, b, c].join(' ')
      exit
    end
  end
  win
end
dfs(K)
puts -1
            
            
            
        
            
siman