結果

問題 No.334 門松ゲーム
ユーザー simansiman
提出日時 2021-03-24 03:25:57
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 675 bytes
コンパイル時間 33 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-05-04 20:55:13
合計ジャッジ時間 5,089 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
12,160 KB
testcase_01 AC 74 ms
12,160 KB
testcase_02 AC 263 ms
12,416 KB
testcase_03 AC 73 ms
12,160 KB
testcase_04 AC 74 ms
12,416 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 127 ms
12,416 KB
testcase_08 WA -
testcase_09 AC 112 ms
12,288 KB
testcase_10 AC 405 ms
12,416 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1,355 ms
12,288 KB
testcase_15 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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