Problem p03160 (python)

Fixed submission:
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# # Top down
# def dp(current):
# 	if ans[current] != None: return ans[current]

# 	if current < 0: return 0
# 	else:
# 		t1 = t2 = int(1e9)
# 		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
# 		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

# 		ans[current] = min(t1, t2)
# 		return ans[current]

# dp(n-1)

for i in range(1, n):
	t1 = t2 = int(1e9)
	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
	ans[i] = min(t1, t2)
# print(ans)
print(ans[n-1])

Buggy submission (verdict: Runtime Error):
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# Top down
def dp(i):
	if i < 0: return 0
	else:
		if ans[i] != None: return ans[i]
		
		t1 = t2 = int(1e9)
		if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
		if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
		ans[i] = min(t1, t2)

		return ans[i]

dp(n-1)

# Bottom up
# for i in range(1, n):
# 	t1 = t2 = int(1e9)
# 	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
# 	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
# 	ans[i] = min(t1, t2)

print(ans[n-1])

Buggy submission (verdict: Runtime Error):
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# Top down
def dp(i):
	if i < 0: return 0
	else:
		if ans[i] != None: return ans[i]

		if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
		if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
		ans[i] = min(t1, t2)
		
		return ans[i]

dp(n-1)

# Bottom up
# for i in range(1, n):
# 	t1 = t2 = int(1e9)
# 	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
# 	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
# 	ans[i] = min(t1, t2)

print(ans[n-1])

Buggy submission (verdict: Runtime Error):
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# Top down
def dp(current):
	if current < 0: return 0
	else:
		if ans[current] != None: return ans[current]
		
		t1 = t2 = int(1e9)
		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

		ans[current] = min(t1, t2)
		return ans[current]

dp(n-1)

# Bottom up
# for i in range(1, n):
# 	t1 = t2 = int(1e9)
# 	if i-1 >= 0: t1 = ans[i-1] + abs(q[i-1] - q[i])
# 	if i-2 >= 0: t2 = ans[i-2] + abs(q[i-2] - q[i])
# 	ans[i] = min(t1, t2)

print(ans[n-1])

Buggy submission (verdict: Runtime Error):
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math 
# import collections
# import string
# ===================================
n = int(input())
q = [int(x) for x in input().split()]
ans = [None for _ in range(n)]
ans[0] = 0

# Top down
def dp(current):
	if ans[current] != None: return ans[current]

	if current < 0: return 0
	else:
		t1 = t2 = int(1e9)
		if current-1 >= 0: t1 = abs(q[current] - q[current-1]) + dp(current-1)
		if current-2 >= 0: t2 = abs(q[current] - q[current-2]) + dp(current-2)

		ans[current] = min(t1, t2)
		return ans[current]

dp(n-1)
print(ans[n-1])