結果

問題 No.334 門松ゲーム
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2016-01-15 23:12:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 16,264 KB
最終ジャッジ日時 2023-10-19 23:33:34
合計ジャッジ時間 3,073 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
16,120 KB
testcase_01 AC 86 ms
16,120 KB
testcase_02 AC 109 ms
16,264 KB
testcase_03 AC 88 ms
16,120 KB
testcase_04 AC 86 ms
16,120 KB
testcase_05 AC 87 ms
16,120 KB
testcase_06 AC 94 ms
16,120 KB
testcase_07 AC 101 ms
16,120 KB
testcase_08 AC 93 ms
16,120 KB
testcase_09 AC 95 ms
16,120 KB
testcase_10 AC 112 ms
16,264 KB
testcase_11 AC 100 ms
16,120 KB
testcase_12 AC 91 ms
16,120 KB
testcase_13 AC 93 ms
16,120 KB
testcase_14 AC 98 ms
16,120 KB
testcase_15 AC 97 ms
16,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:57: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

# Here your code !

N=gets.to_i
@ks=gets.split.map(&:to_i)
# p @ks
@memo={}
def go(mask, first)
    # puts "start: mask=#{mask}"
    if @memo[mask] != nil
        return @memo[mask]
    end

    result = false
    (0...N).each{|a|

        if(mask[a])
            next
        end
        mask[a]=true
        (a+1...N).each{|b|
            if(mask[b])
                next
            end
            mask[b]=true
            (b+1...N).each{|c|

                if(mask[c])
                    next
                end
                mask[c]=true
                #puts "c: mask=#{mask}, a,b,c=#{a}, #{b}, #{c}"

                if @ks[a]==@ks[b] || @ks[b]==@ks[c] || (@ks[b]!=([@ks[a],@ks[b],@ks[c]]).max && @ks[b]!=([@ks[a],@ks[b],@ks[c]]).min)
                    mask[c]=nil
                    next
                end
                ret = go(mask, false)
                if ret == false
                    result = true
                    if first
                        puts [a,b,c].join(" ")
                        exit
                    end
                end
                mask[c]=nil
            }
            mask[b]=nil
        }
        mask[a]=nil
    }
    # puts "end: mask=#{mask}, result=#{result}"
    @memo[mask]=result
    return result
end

go(Array.new(N,nil), true)
puts -1
0