結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-15 20:49:30 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 105 ms / 2,000 ms |
| コード長 | 717 bytes |
| コンパイル時間 | 39 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,544 KB |
| 最終ジャッジ日時 | 2024-09-22 07:08:49 |
| 合計ジャッジ時間 | 2,349 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
コンパイルメッセージ
Syntax OK
ソースコード
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