結果

問題 No.334 門松ゲーム
ユーザー simansiman
提出日時 2021-03-24 03:25:57
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 675 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-11-26 11:11:22
合計ジャッジ時間 5,648 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:45: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

N = gets.to_i
K = gets.split.map(&:to_i)

def dfs(nums, turn = 0)
  l = nums.size
  kadomatsu_cnt = 0
  win = turn.odd?

  [*0...l].combination(3) do |a, b, c|
    next if nums[a] < nums[b] && nums[b] < nums[c]
    next if nums[a] > nums[b] && nums[b] > nums[c]

    kadomatsu_cnt += 1
    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

  if turn.even?
    win
  else
    kadomatsu_cnt == 0
  end
end

dfs(K)

puts -1
0