Problem p03160 (python)

Fixed submission:
# N = int(input())
# h = list(map(int, input().split()))
# 
# #大きな値
# INF = 9999
# 
# # DPtable
# dp = [INF]*9999
# 
# #初期条件
# dp[0] = 0
# dp[1] = abs(h[1]-h[0])
# 
# #ループ
# for i in range(N):
#     if i == 0 or i == 1:
#         continue
#     else:
#         dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
# 
# print(dp[N-1])

N = int(input())
h = list(map(int, input().split()))
dp = [10 ** 10 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))

# #大きな値
INF = 10**10
#
# # DPtable
dp = [INF]*10000

# dp = [10**10 for _ in range(N)]


#初期条件
dp[0] = 0
dp[1] = abs(h[1]-h[0])

#ループ
for i in range(N):
    if i == 0 or i == 1:
        continue
    else:
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))


print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))

#大きな値
INF = 10**10

# DPtable
dp = [INF]*10000

#初期条件
dp[0] = 0
dp[1] = abs(h[1]-h[0])

#ループ
for i in range(N):
    if i == 0 or i == 1:
        continue
    else:
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))

#大きな値
INF = 9999

# DPtable
dp = [INF]*9999

#初期条件
dp[0] = 0
dp[1] = abs(h[1]-h[0])

#ループ
for i in range(2, N):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))

#大きな値
INF = 9999

# DPtable
dp = [INF]*9999

#初期条件
dp[0] = 0
dp[1] = abs(h[1]-h[0])

#ループ
for i in range(N):
    if i == 0 or i == 1:
        continue
    else:
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))

#大きな値
INF = 9999

# DPtable
dp = [INF]*10000

#初期条件
dp[0] = 0
dp[1] = abs(h[1]-h[0])

#ループ
for i in range(N):
    if i == 0 or i == 1:
        continue
    else:
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))



#大きな値
INF = 9999

# DPtable
dp = [INF]*10000

#初期条件
dp[0] = 0
dp[1] = abs(h[1]-h[0])

#ループ
for i in range(N):
    if i == 0 or i == 1:
        continue
    else:
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

# print(dp[0:N])

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))


# DP 最小化問題用 change minimum
# 2つの引数をとり，1つめより2つめが小さかったら更新する

def chmin(array, x):
    if (array > x):
        array = x
        return array
    return array

#大きな値
INF = 9999

# DPtable
dp = [INF]*10000

#初期条件
dp[0] = 0

#ループ
for i in range(N):
    if i == 0:
        continue
    else:
        x = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
        dp[i] = x
        if i > 1:
            x1 = chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]))
            dp[i] = x1

# print(dp[0:N])

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))


# DP 最小化問題用 change minimum
# 2つの引数をとり，1つめより2つめが小さかったら更新する

def chmin(array, x):
    if (array > x):
        array = x
        return array
    return array

#大きな値
INF = 9999

# DPtable
dp = [INF]*10000

#初期条件
dp[0] = 0

#ループ
for i in range(N):
    if i == 0:
        continue
    else:
        x = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
        dp[i] = x
        if i > 1:
            x1 = chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]))
            dp[i] = x1

# print(dp[0:N])

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))


# DP 最小化問題用 change minimum
# 2つの引数をとり，1つめより2つめが小さかったら更新する

def chmin(array, x):
    if (array > x):
        array = x
        return array
    return array


# DP 最大化問題用 change maximum

def chmax(array, x):
    if (array > x):
        array = x
        return True
    return False


#大きな値
INF = 9999

# DPtable
dp = [INF]*10000

#初期条件
dp[0] = 0

#ループ
for i in range(N):
    if i == 0:
        continue
    else:
        dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
        if i > 1:
            dp[i] = chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]))

# print(dp[0:N])
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))


# DP 最小化問題用 change minimum
# 2つの引数をとり，1つめより2つめが小さかったら更新する

def chmin(array, x):
    if (array > x):
        array = x
        return array
    return array


# DP 最大化問題用 change maximum

def chmax(array, x):
    if (array > x):
        array = x
        return True
    return False


#大きな値
INF = 999999

# DPtable
dp = [INF]*10000

#初期条件
dp[0] = 0

#ループ
for i in range(N):
    if i == 0:
        continue
    else:
        dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
        if i>1:
            dp[i] = chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]))

# print(dp[0:N])
print(dp[N-1])