結果

問題 No.334 門松ゲーム
ユーザー cympfhcympfh
提出日時 2016-02-15 20:49:30
言語 Ruby
(3.3.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 11,908 KB
実行使用メモリ 16,276 KB
最終ジャッジ日時 2023-10-22 05:49:41
合計ジャッジ時間 3,308 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
16,120 KB
testcase_01 AC 84 ms
16,120 KB
testcase_02 AC 94 ms
16,268 KB
testcase_03 AC 88 ms
16,120 KB
testcase_04 AC 83 ms
16,120 KB
testcase_05 AC 88 ms
16,120 KB
testcase_06 AC 89 ms
16,120 KB
testcase_07 AC 91 ms
16,260 KB
testcase_08 AC 91 ms
16,120 KB
testcase_09 AC 91 ms
16,268 KB
testcase_10 AC 98 ms
16,268 KB
testcase_11 AC 91 ms
16,268 KB
testcase_12 AC 107 ms
16,268 KB
testcase_13 AC 94 ms
16,272 KB
testcase_14 AC 91 ms
16,276 KB
testcase_15 AC 103 ms
16,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i
Ks=gets.chomp.split.map(&:to_i)
$memo = []
$ans = -1

def rec j
  return if $memo[j] != nil
  $memo[j] = false
  ns = []
  (0...N).each{|i|
    if (j & (1 << i)) == 0
      ns << i
    end
  }
  for cs in ns.combination(3)
    ok=false
    if Ks[cs[0]] < Ks[cs[1]] and Ks[cs[1]] > Ks[cs[2]]
      ok=true
    end
    if Ks[cs[0]] > Ks[cs[1]] and Ks[cs[1]] < Ks[cs[2]]
      ok=true
    end
    if ok
      j2 = j | (1<<cs[0]) | (1<<cs[1]) | (1<<cs[2])
      rec j2
      if $memo[j2] == false
        $memo[j] = true
        $ans = cs.join(' ') if (j==0) and ($ans == -1)
      end
    end
  end
end

rec 0
# (0..10000).each{|i|
#   if $memo[i] != nil
#     puts "#{i}: #{$memo[i]}"
#   end
# }
puts $ans
0