結果

問題 No.334 門松ゲーム
ユーザー yozayoza
提出日時 2016-01-16 01:38:25
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 11,952 KB
実行使用メモリ 16,132 KB
最終ジャッジ日時 2023-10-19 23:53:39
合計ジャッジ時間 2,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
16,132 KB
testcase_01 AC 86 ms
16,132 KB
testcase_02 AC 89 ms
16,132 KB
testcase_03 AC 85 ms
16,132 KB
testcase_04 AC 86 ms
16,132 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 90 ms
16,132 KB
testcase_08 AC 87 ms
16,132 KB
testcase_09 AC 86 ms
16,132 KB
testcase_10 AC 89 ms
16,132 KB
testcase_11 AC 88 ms
16,132 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 87 ms
16,132 KB
testcase_15 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
k_list = gets.split.map(&:to_i)

def kadomatsu?(a, b, c)
  if (a <= b and b <= c) or (c <= b and b <= a)
    return false
  else
    return true
  end
end

k_set_list = [];
0.upto(n-3) do |i|
  (i+1).upto(n-2) do |j|
    (j+1).upto(n-1) do |k|
      if kadomatsu?(k_list[i], k_list[j], k_list[k])
        k_set_list << [i, j, k]
      end
    end
  end
end

def dfs(depth, used, k_set_list)
  if depth == 0
    k_set_list.each_with_index do |k_set, i|
      if dfs(depth + 1, [i], k_set_list)
        return k_set.join(' ')
      end
    end
    return '-1'
  else
    return k_set_list.each_with_index.all? do |k_set, i|
      flag = used.all? do |j|
        next false if j == i
        next k_set_list[j].all? {|k| not k_set.include?(k) }
      end
      if flag
        next dfs(depth + 1, used + [i], k_set_list)
      else
        next depth % 2 == 1 ? true : false
      end
    end
  end
end

puts dfs(0, [], k_set_list)
0