提出 #4306521


ソースコード 拡げる

n, m = gets.split.map(&:to_i)
a = gets.split

num = {}
[0, 2, 5, 5, 4, 5, 6, 3, 7, 6].each_with_index{|i, idx| num[idx.to_s] = i }

INF = 1e8.to_i
dp = Array.new(n+1, -INF)
dp[0] = 0

for i in 1..n
    maxcol = -INF
    for aj in a
        num_aj = num[aj]

        next if i - num_aj < 0

        if dp[i - num_aj] + 1 > maxcol
            maxcol = dp[i - num_aj] + 1
        end
    end

    if maxcol > 0
        dp[i] = maxcol
    end
end

a = a.sort.reverse
match = n
remcol = dp[n]
ans = ""
while match > 0
    for ai in a
        num_ai = num[ai]

        next if match - num_ai < 0

        if dp[match - num_ai] == remcol - 1
            ans += ai
            remcol -= 1
            match -= num_ai
            break
        end
    end
end

puts ans

提出情報

提出日時
問題 D - Match Matching
ユーザ vpplcb
言語 Ruby (2.3.3)
得点 400
コード長 808 Byte
結果 AC
実行時間 39 ms
メモリ 9852 KiB

コンパイルエラー

./Main.rb:1: warning: assigned but unused variable - m

ジャッジ結果

セット名 All Sample
得点 / 配点 400 / 400 0 / 0
結果
AC × 29
AC × 3
セット名 テストケース
All 0_random_1, 0_random_2, 0_random_3, 0_random_4, 0_random_5, 0_random_6, 0_random_7, 0_random_8, 1_normal_1, 1_normal_2, 1_normal_3, 1_normal_4, 1_normal_5, 1_normal_6, 2_corner_1, 2_corner_2, 2_corner_3, 2_corner_4, 2_corner_5, 2_corner_6, 3_hand_1, 3_hand_2, 3_hand_3, 3_hand_4, 3_hand_5, 3_hand_6, sample_01, sample_02, sample_03
Sample sample_01, sample_02, sample_03
ケース名 結果 実行時間 メモリ
0_random_1 AC 7 ms 1788 KiB
0_random_2 AC 7 ms 1788 KiB
0_random_3 AC 10 ms 1916 KiB
0_random_4 AC 24 ms 9596 KiB
0_random_5 AC 28 ms 6780 KiB
0_random_6 AC 20 ms 4476 KiB
0_random_7 AC 11 ms 4860 KiB
0_random_8 AC 8 ms 1788 KiB
1_normal_1 AC 11 ms 2172 KiB
1_normal_2 AC 21 ms 3324 KiB
1_normal_3 AC 14 ms 2812 KiB
1_normal_4 AC 23 ms 7036 KiB
1_normal_5 AC 18 ms 7676 KiB
1_normal_6 AC 16 ms 2428 KiB
2_corner_1 AC 11 ms 2172 KiB
2_corner_2 AC 8 ms 1788 KiB
2_corner_3 AC 18 ms 3068 KiB
2_corner_4 AC 9 ms 1916 KiB
2_corner_5 AC 8 ms 1788 KiB
2_corner_6 AC 11 ms 2300 KiB
3_hand_1 AC 15 ms 3196 KiB
3_hand_2 AC 7 ms 1788 KiB
3_hand_3 AC 7 ms 1788 KiB
3_hand_4 AC 7 ms 1788 KiB
3_hand_5 AC 7 ms 1788 KiB
3_hand_6 AC 39 ms 9852 KiB
sample_01 AC 7 ms 1788 KiB
sample_02 AC 7 ms 1788 KiB
sample_03 AC 7 ms 1788 KiB