結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー finefine
提出日時 2016-03-27 01:18:13
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 553 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-04-10 00:14:21
合計ジャッジ時間 4,500 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:26: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

def sol a, h
    if a.size < 3
        return 0
    end
    r = a.pop
    l = a.shift 
    h[l] -= 1
    h[r] -= 1
    tmp = 0
    idx = 10000
    a.size.times{|i|
        if [l,a[i],r].uniq.size == 3 && tmp < h[a[i]]
            tmp = h[a[i]]
            idx = i
        end
        }
    if idx == 10000
        return 0
    end
    a.delete_at(idx)
    h[idx] -= 1
    return sol(a, h) + 1
end

gets.to_i.times{
    n = gets.to_i
    a = gets.split.map(&:to_i).sort
    h = Hash.new(0)
    a.each{|x|
        h[x] += 1
        }
    p sol(a, h)
    }
0