結果

問題 No.334 門松ゲーム
ユーザー simansiman
提出日時 2021-03-24 03:39:24
言語 Ruby
(3.3.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-05-04 21:05:19
合計ジャッジ時間 2,377 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
12,160 KB
testcase_01 AC 89 ms
12,160 KB
testcase_02 AC 157 ms
12,544 KB
testcase_03 AC 76 ms
12,160 KB
testcase_04 AC 78 ms
12,288 KB
testcase_05 AC 78 ms
12,288 KB
testcase_06 AC 95 ms
12,416 KB
testcase_07 AC 107 ms
12,288 KB
testcase_08 AC 86 ms
12,416 KB
testcase_09 AC 95 ms
12,288 KB
testcase_10 AC 134 ms
12,416 KB
testcase_11 AC 115 ms
12,288 KB
testcase_12 AC 88 ms
12,288 KB
testcase_13 AC 82 ms
12,288 KB
testcase_14 AC 139 ms
12,288 KB
testcase_15 AC 105 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:44: 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]
    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]

    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

  win
end

dfs(K)

puts -1
0