Problem p03161 (python)

Fixed submission:
n, k = map(int, input().split())
arr = list(map(int, input().split()))

# dp初期化
dp = [float("inf")] * n
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[j] + abs(arr[i] - arr[j]) for j in range(max(i - k, 0), i))

print(dp[n - 1])

Buggy submission (verdict: Runtime Error):
from numba import jit

@jit
def solve(n, k, arr):
    INF = 1 << 60
    dp = [INF] * (n + 1000)

    dp[1] = 0

    for i in range(1, n):
        for k in range(1, k + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(arr[i + k] - arr[i]))

    return dp[n]


n, k = map(int, input().split())
arr = [0] + list(map(int, input().split())) + [0] * 1000

print(solve(n, k, arr))

Buggy submission (verdict: Runtime Error):
from numba import jit


@jit
def solve(n, k, arr):
    INF = 1 << 60
    dp = [INF] * (n + 1000)

    dp[1] = 0

    for i in range(1, n):
        for k in range(1, k + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(arr[i + k] - arr[i]))

    return dp[n]


n, k = map(int, input().split())
arr = [0] + list(map(int, input().split())) + [0] * 1000

print(solve(n, k, arr))

Buggy submission (verdict: Runtime Error):
from numba import njit


@njit(cache=True)
def solve(n, k, arr):
    INF = 1 << 60
    dp = [INF] * (n + 1000)

    dp[1] = 0

    for i in range(1, n):
        for k in range(1, k + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(arr[i + k] - arr[i]))

    return dp[n]


n, k = map(int, input().split())
arr = [0] + list(map(int, input().split())) + [0] * 1000

print(solve(n, k, arr))

Buggy submission (verdict: Runtime Error):
from numba import jit

n, k = map(int, input().split())
arr = [0] + list(map(int, input().split())) + [0] * 1000


@jit
def solve(n, k, arr):
    INF = 1 << 60
    dp = [INF] * (n + 1000)
    dp[1] = 0

    for i in range(1, n):
        for k in range(1, k + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(arr[i + k] - arr[i]))

    return dp[n]


print(solve(n, k, arr))

Buggy submission (verdict: Runtime Error):
from numba import njit

n, k = map(int, input().split())
arr = [0] + list(map(int, input().split())) + [0] * 1000


@njit
def solve(n, k, arr):
    INF = 1 << 60
    dp = [INF] * (n + 1000)
    dp[1] = 0

    for i in range(1, n):
        for k in range(1, k + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(arr[i + k] - arr[i]))

    return dp[n]


print(solve(n, k, arr))

Buggy submission (verdict: Runtime Error):
from numba import jit, f8, i8, b1, void

n, k = map(int, input().split())
arr = list(map(int, input().split()))


@jit(i8(i8[:]))
def solve(arr):
    INF = 1 << 40

    # dp初期化
    dp = [INF] * n
    dp[0] = 0

    for i in range(1, n):
        dp[i] = min(dp[j] + abs(arr[i] - arr[j])
                    for j in range(max(i - k, 0), i))

    return dp([n - 1])


print(solve(arr))

Buggy submission (verdict: Runtime Error):
from numba import njit

n, k = map(int, input().split())
arr = list(map(int, input().split()))


@njit
def main():
    INF = 1 << 40

    # dp初期化
    dp = [INF] * n
    dp[0] = 0

    for i in range(1, n):
        dp[i] = min(dp[j] + abs(arr[i] - arr[j])
                    for j in range(max(i - k, 0), i))

    print(dp[n - 1])

Buggy submission (verdict: Runtime Error):
import numpy as np
 
n, k = map(int, input().split())
arr = list(map(int, input().split())) + [0] * k
 
INF = 1 << 60
 
# dp初期化
dp = [INF] * (n + k)
dp[0] = 0
 
for i in range(n):
    for j in range(1, k + 1):
        dp[i + j] = min(dp[i + j], dp[i] + abs(arr[i + j] - arr[i]))
 
print(dp[n - 1])