結果

問題 No.334 門松ゲーム
ユーザー simansiman
提出日時 2021-03-24 03:39:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 11,384 KB
実行使用メモリ 15,500 KB
最終ジャッジ日時 2023-08-17 14:28:10
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,148 KB
testcase_01 AC 80 ms
15,056 KB
testcase_02 AC 155 ms
15,488 KB
testcase_03 AC 85 ms
15,236 KB
testcase_04 AC 83 ms
15,156 KB
testcase_05 AC 79 ms
15,188 KB
testcase_06 AC 93 ms
15,440 KB
testcase_07 AC 109 ms
15,356 KB
testcase_08 AC 88 ms
15,356 KB
testcase_09 AC 99 ms
15,280 KB
testcase_10 AC 143 ms
15,468 KB
testcase_11 AC 107 ms
15,500 KB
testcase_12 AC 82 ms
15,160 KB
testcase_13 AC 82 ms
15,312 KB
testcase_14 AC 144 ms
15,292 KB
testcase_15 AC 104 ms
15,392 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:42: 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
  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
0