Problem p03160 (python)

Fixed submission:
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [0 for n in range(10 ** 5 * 2)]
a = 0
while dp[num-1] == 0:
  a+= 1
  if a == num:
    break
  if a == 1:
    dp[a] = abs(height[a]-height[a-1])
  else:
    dp[a] = min(abs(height[a]-height[a-1])+dp[a-1],abs(height[a]-height[a-2])+dp[a-2])
print(dp[num-1])

Buggy submission (verdict: Runtime Error):
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [0 for n in range(10 ** 5 * 2)]
a = 0
while dp[num-1] == 0:
  a+= 1
  if a == 1:
    dp[a] = abs(height[a]-height[a-1])
  else:
    dp[a] = min(abs(height[a]-height[a-1])+dp[a-1],abs(height[a]-height[a-2])+dp[a-2])
print(dp[num-1])

Buggy submission (verdict: Runtime Error):
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [0 for n in range(10 ** 5 * 2)]
def jump(a,now):
  if dp[a] != 0:
    return dp[a]
  if a == num:
    res = 0
  elif a+2 > num:
    res = jump(a+1,height[a])+abs(now-height[a])
  else:
    res = min(jump(a+1,height[a])+abs(now-height[a]),jump(a+2,height[a+1])+abs(now-height[a+1]))
  dp[a] = res
  return res
print(jump(1,height[0]))

Buggy submission (verdict: Runtime Error):
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [{} for n in range(10 ** 5 * 2)]
def jump(a,now):
  if now in dp[a]:
    return dp[a][now]
  if a == num:
    res = 0
  elif a+2 > num:
    res = jump(a+1,height[a])+abs(now-height[a])
  else:
    res = min(jump(a+1,height[a])+abs(now-height[a]),jump(a+2,height[a+1])+abs(now-height[a+1]))
  dp[a][now] = res
  return res
print(jump(1,height[0]))

Buggy submission (verdict: Runtime Error):
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [{} for n in range(1000000)]
def jump(a,now):
  if now in dp[a]:
    return dp[a][now]
  if a == num:
    res = 0
  elif a+2 > num:
    res = jump(a+1,height[a])+abs(now-height[a])
  else:
    res = min(jump(a+1,height[a])+abs(now-height[a]),jump(a+2,height[a+1])+abs(now-height[a+1]))
  dp[a][now] = res
  return res
print(jump(1,height[0]))

Buggy submission (verdict: Runtime Error):
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [{} for n in range(10000)]
def jump(a,now):
  if now in dp[a]:
    return dp[a][now]
  if a == num:
    res = 0
  elif a+2 > num:
    res = jump(a+1,height[a])+abs(now-height[a])
  else:
    res = min(jump(a+1,height[a])+abs(now-height[a]),jump(a+2,height[a+1])+abs(now-height[a+1]))
  dp[a][now] = res
  return res
print(jump(1,height[0]))

Buggy submission (verdict: Runtime Error):
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [{}]
def jump(a,cost,now):
  if cost in dp[a]:
    return dp[a][cost]
  elif a == num:
    res = 0
  else:
    res = min(jump(a+1,cost+abs(now-height[a+1],height[a+1]),jump(a+2,cost+abs(now-height[a+2],height[a+2])
print(jump(1,0,height[0])

Buggy submission (verdict: Runtime Error):
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [{} for n in range(10000)]
def jump(a,cost,now):
  print(cost)
  if cost in dp[a]:
    return dp[a][cost]
  elif a-1 == num:
	res = 0
  elif a+2 < num:
    res = min(jump(a+1,cost+abs(now-height[a+1]),height[a+1]),jump(a+2,cost+abs(now-height[a+2]),height[a+2]))
  else:
    res = jump(a+1,cost+abs(now-height[a+1]),height[a+1])
  dp[a][cost] = res
  return res
print(jump(1,0,height[0]))

Buggy submission (verdict: Runtime Error):
num = int(input())
List = input().split(" ")
height = [int(n) for n in List]
dp = [{}]
def jump(a,cost,now):
  if cost in dp[a]:
    return dp[a][cost]
  elif a == num:
    res = 0
  else:
    res = min(jump(a+1,cost+abs(now-height[a+1],height[a+1]),jump(a+2,cost+abs(now-height[a+2],height[a+2])
print(jump(1,0,height[0])