結果
問題 | No.334 門松ゲーム |
ユーザー | yoza |
提出日時 | 2016-01-16 02:11:36 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 522 ms / 2,000 ms |
コード長 | 966 bytes |
コンパイル時間 | 66 ms |
コンパイル使用メモリ | 11,896 KB |
実行使用メモリ | 16,180 KB |
最終ジャッジ日時 | 2023-10-19 23:53:58 |
合計ジャッジ時間 | 3,284 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 93 ms
16,076 KB |
testcase_01 | AC | 89 ms
16,076 KB |
testcase_02 | AC | 272 ms
16,180 KB |
testcase_03 | AC | 88 ms
16,072 KB |
testcase_04 | AC | 89 ms
16,076 KB |
testcase_05 | AC | 90 ms
16,076 KB |
testcase_06 | AC | 161 ms
16,180 KB |
testcase_07 | AC | 182 ms
16,180 KB |
testcase_08 | AC | 117 ms
16,076 KB |
testcase_09 | AC | 108 ms
16,076 KB |
testcase_10 | AC | 522 ms
16,180 KB |
testcase_11 | AC | 109 ms
16,076 KB |
testcase_12 | AC | 117 ms
16,076 KB |
testcase_13 | AC | 108 ms
16,076 KB |
testcase_14 | AC | 148 ms
16,180 KB |
testcase_15 | AC | 185 ms
16,076 KB |
コンパイルメッセージ
Syntax OK
ソースコード
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.send("#{depth % 2 == 1 ? 'all' : 'any'}?") do |k_set, i| flag = used.all? do |j| next false if j == i k_set_list[j].all? {|k| not k_set.include?(k) } end if flag dfs(depth + 1, used + [i], k_set_list) else depth % 2 == 1 ? true : false end end end end puts dfs(0, [], k_set_list)