結果

問題 No.266 最終進化を目指せ
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-07-12 05:59:20
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,184 bytes
コンパイル時間 46 ms
コンパイル使用メモリ 6,644 KB
実行使用メモリ 6,048 KB
最終ジャッジ日時 2023-09-22 14:18:37
合計ジャッジ時間 1,385 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,876 KB
testcase_01 AC 11 ms
5,844 KB
testcase_02 AC 10 ms
5,888 KB
testcase_03 AC 10 ms
5,964 KB
testcase_04 AC 10 ms
5,980 KB
testcase_05 AC 10 ms
5,856 KB
testcase_06 AC 11 ms
6,044 KB
testcase_07 AC 10 ms
5,968 KB
testcase_08 AC 11 ms
5,956 KB
testcase_09 AC 11 ms
6,048 KB
testcase_10 AC 11 ms
5,964 KB
testcase_11 AC 10 ms
5,976 KB
testcase_12 AC 10 ms
5,960 KB
testcase_13 AC 11 ms
5,976 KB
testcase_14 AC 11 ms
5,888 KB
testcase_15 AC 11 ms
5,932 KB
testcase_16 AC 11 ms
5,964 KB
testcase_17 AC 10 ms
5,964 KB
testcase_18 AC 11 ms
5,932 KB
testcase_19 AC 11 ms
5,988 KB
testcase_20 AC 11 ms
5,960 KB
testcase_21 AC 11 ms
5,968 KB
testcase_22 AC 11 ms
5,940 KB
testcase_23 AC 11 ms
5,892 KB
testcase_24 AC 10 ms
5,864 KB
testcase_25 AC 11 ms
5,996 KB
testcase_26 AC 11 ms
5,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
# -*- coding: utf-8 -*-
n = int(raw_input())
s = map(int, raw_input().split())

dp = [[float('inf') for _ in xrange(s[-1] + 1)] for _ in xrange(n+1)]

# 潜在能力が存在しえない場所はNoneで埋めておく
for i, row in enumerate(dp):
    for j in xrange(s[i] + 1, len(row)):
        row[j] = None

# 潜在能力をx個付与させた最初の形態は x+1 だけカードが必要になる
for j in xrange(len(dp[0])):
    if dp[0][j] != None:
        dp[0][j] = j + 1

# i番目の形態の潜在能力0個は i+1 だけカードが必要になる(iは0から)
for i in xrange(len(dp)):
    dp[i][0] = i + 1

for i in xrange(len(dp)):
    for j in xrange(len(dp[i])):
        if dp[i][j] == None:
            continue
        # 1個前の進化状態のカード(潜在能力j個)を進化させる
        if dp[i-1][j] != None:
            dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
        cand = [(e, j-1-e) for e in xrange(j)]
        for p, q in cand:
            # 潜在能力p個とq個のカードをマージして潜在能力j個のカードを作る
            dp[i][j] = min(dp[i][j], dp[i][p] + dp[i][q])

print ' '.join(map(str, dp[n]))
0