結果

問題 No.1077 Noelちゃんと星々4
ユーザー tamatotamato
提出日時 2020-06-12 21:31:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 475 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,564 KB
実行使用メモリ 155,412 KB
最終ジャッジ日時 2023-09-06 09:52:02
合計ジャッジ時間 5,834 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,892 KB
testcase_01 AC 82 ms
76,228 KB
testcase_02 AC 262 ms
130,748 KB
testcase_03 AC 300 ms
146,632 KB
testcase_04 AC 151 ms
97,788 KB
testcase_05 AC 134 ms
92,632 KB
testcase_06 AC 175 ms
104,316 KB
testcase_07 AC 183 ms
108,788 KB
testcase_08 AC 160 ms
99,928 KB
testcase_09 AC 151 ms
96,636 KB
testcase_10 AC 307 ms
146,480 KB
testcase_11 AC 229 ms
122,168 KB
testcase_12 AC 206 ms
114,476 KB
testcase_13 AC 135 ms
91,672 KB
testcase_14 AC 300 ms
145,064 KB
testcase_15 AC 203 ms
113,008 KB
testcase_16 AC 163 ms
100,600 KB
testcase_17 AC 216 ms
117,724 KB
testcase_18 AC 316 ms
147,992 KB
testcase_19 AC 134 ms
91,180 KB
testcase_20 AC 82 ms
76,236 KB
testcase_21 AC 333 ms
155,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9
inf = 10**10


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    H = list(map(int, input().split()))

    dp = [[inf] * (10**4+1) for _ in range(N+1)]
    dp[0][1] = 0
    for i in range(N):
        h = H[i]
        m = inf
        for j in range(1, 10001):
            m = min(m, dp[i][j])
            dp[i+1][j] = min(dp[i+1][j], m + abs(h - j))
    print(min(dp[-1]))


if __name__ == '__main__':
    main()
0