problem_id
stringclasses
100 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
6
806
p03160
s156743599
Wrong Answer
n = int(input()) h = list(map(int,input().split())) dp = [float("inf") for _ in range(n)] dp[0] = 0 for i in range(n-1): dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i])) if i<n-2: dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i])) print(dp[n-2])
p03160
s720974051
Wrong Answer
n=int(input()) h=list(map(int,input().split())) dp=[0]*n dp[0]=0 dp[1]=abs(h[1]-h[0]) for i in range(n-2): dp[i+2]=min(dp[i]+abs(h[i+2]-h[i]),dp[i+1]+abs(h[i+2]-h[i])) print(dp[n-1])
p03160
s965568730
Wrong Answer
# A # 若干解説を見た # 2020/04/27 17:5- n = int(input()) h = list(map(int, input().split())) s = [0]*n for i in range(1, n): if i == 1: s[i] = h[i] - h[i-1] else: s[i] = min(s[i-2] + abs(h[i]-h[i-2]), s[i-1] + abs(h[i]-h[i-1])) print(s[-1])
p03160
s766198130
Wrong Answer
n = int(input()) arr = list(map(int,input().split())) dp=[arr[-1]] som=0 i=n-1 while i!=0: op1 = abs(dp[-1]-arr[i-1]) op2 = 10**18 if i-2>=0: op2 = abs(dp[-1]-arr[i-2]) minm = min(op1,op2) som+=minm if minm==op1: dp.append(arr[i-1]) i-=1 else: dp.append(arr[i-2]) i-=2 print(som)
p03160
s079934068
Wrong Answer
n=int(input()) l=list(map(int, input().split())) inf=10**12 dp=[inf]*n dp[0]=0 dp[1]=abs(l[0]-l[1]) for i in range(n-2): dp[i+2]=min(dp[i]+abs(l[i+2]-l[i]),dp[i+1]+abs(l[i+2]-l[i+1])) print(dp) print(dp[-1])
p03160
s660016136
Wrong Answer
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines read = sys.stdin.buffer.read sys.setrecursionlimit(10 ** 7) INF = float('inf') N = int(readline().rstrip()) H = list(map(int, readline().split())) LIM = 10 ** 4 dp = [LIM] * N dp[0] = 0 for i in range(N): if i+1 < N: dp[i+1] = min(dp[i+1], dp[i] + abs(H[i] - H[i+1])) if i+2 < N: dp[i+2] = min(dp[i+2], dp[i] + abs(H[i] - H[i+2])) ans = dp[N-1] print(ans)
p03160
s130576383
Wrong Answer
N = int(input()) h = list(map(int,input().split())) cost = [1000000]*N cost[0] = 0 for i in range(1, N): cost[i] = min((abs(h[i-1] - h[i]) + cost[i-1]),cost[i]) if i >= 2: cost[i] = min((abs(h[i-2] - h[i]) + cost[i-2]), cost[i]) print(cost[-1])
p03160
s141665984
Wrong Answer
#DP カエルの奴 A  配るDP N=int(input()) S=list(map(int,input().split())) for i in range(100000): S.append(100000000) DP=[100000000]*100010 DP[0]=0 for i in range(N): if DP[i]+abs(S[i]-S[i+1])<DP[i+1]: DP[i+1]=DP[i]+abs(S[i]-S[i+1]) if DP[i]+abs(S[i]-S[i+2])<DP[i+2]: DP[i+2]=DP[i]+abs(S[i]-S[i+2]) print(DP[N-1])
p03160
s917459556
Wrong Answer
N = int(input()) H = list(map(int, input().split())) INF = 10 ** 6 dp = [INF] * N dp[0] = 0 for i in range(1, N): dp[i] = min(dp[i], dp[i-1] + abs(H[i] - H[i-1])) if i > 1: dp[i] = min(dp[i], dp[i-2] + abs(H[i] - H[i-2])) print(dp[N-1])
p03160
s836523242
Wrong Answer
""" author : halo2halo date : 4, Feb, 2020 """ import sys # import itertools # import math # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 10 ** 9 N, *H = map(int, read().split()) dp = [INF] * N dp[0] = 0 for i in range(0, N-2): print(i) dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1])) dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2])) print(dp[N-1])
p03160
s385900661
Wrong Answer
n=int(input()) A=list(map(int,input().split())) sum=0 for i in range(n-2): a=abs(A[i]-A[i+1]) b=abs(A[i]-A[i+2]) sum+=min(a,b) print(sum)
p03160
s558019944
Wrong Answer
hight = [2, 9, 4, 5, 1, 6, 10] lis = [0, hight[1]-hight[0]] for i in range(len(hight)): if i == 0 or i == 1: pass else: lis.append(min(lis[i-2] + abs(hight[i]-hight[i-2]), lis[i-1] + abs(hight[i]-hight[i-1]))) print(lis)
p03160
s062758479
Wrong Answer
def chmin(dp, i, target): if (dp[i] > target): dp[i] = target n = int(input()) h = [i for i in input().split(" ")] dp =[10**5] * n dp[0] = 0 for i in range(1, n): chmin(dp, i, dp[i - 1] + abs(int(h[i]) - int(h[i - 1]))) if i > 1: chmin(dp, i, dp[i - 2] + abs(int(h[i]) - int(h[i - 2]))) print(dp[n - 1])
p03160
s930759725
Wrong Answer
def chmin(dp, i, target): if (dp[i] > target): dp[i] = target n = int(input()) h = [i for i in input().split(" ")] dp =[100010] * n dp[0] = 0 for i in range(1, n): chmin(dp, i, dp[i - 1] + abs(int(h[i]) - int(h[i - 1]))) if i > 1: chmin(dp, i, dp[i - 2] + abs(int(h[i]) - int(h[i - 2]))) print(dp[n - 1])
p03160
s465714205
Wrong Answer
n = int(input()) h = list(map(int,input().split())) dp = [10 ** 5 for i in range(n)] dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(n-2): dp[i+2] = min(dp[i] + abs(h[i+2] - h[0]), dp[i+1] + abs(h[i+1] - h[i])) print(dp[-1])
p03160
s538308569
Wrong Answer
n = int(input()) h = list(map(int, input().split())) INF = 1 << 30 dp = [INF] * n dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, n): pos = h[i] if abs(h[i-2] - pos) < abs(h[i-1] - pos): diff = abs(h[i-2] - pos) dp[i] = dp[i-2] + diff else: diff = abs(h[i-1] - pos) dp[i] = dp[i-1] + diff print(dp[-1])
p03160
s966203095
Wrong Answer
N = int(input()) h = list(map(int, input().split())) DP = [10**10 for _ in range(N)] DP[0] = 0 DP[1] = h[1]-h[0] for i in range(2, N): DP[i] = min(DP[i-1]+abs(h[i-1]-h[i]), DP[i-2]+abs(h[i-2]-h[i])) #print(DP) print(DP[N-1])
p03160
s100895254
Wrong Answer
N = int(input()) a = [int(x) for x in input().split()] def dp(N,a): F = [0]*(len(a)+1) F[0]=0 F[1]=0 F[2]=abs(a[1]-a[0]) if N == 1: return F[0] elif N == 2: return F[1] for n in range(2,N+1): F[n] = min(F[n-1] + abs(a[n-1]-a[n-2]),F[n-2]+abs(a[n-1]-a[n-3])) print(F) return F[-1] print(dp(N,a))
p03160
s786145564
Wrong Answer
# coding:utf-8 N = int(input()) h = [int(x) for x in input().split()] inf = 100000000 dp = [inf for x in range(N)] dp[0] = 0 for i in range(1, N): dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1])) if i >= 2: dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print(dp[N-1])
p03160
s903960479
Wrong Answer
N = int(input()) A = list(map(int, input().split())) dp = [0 for _ in range(len(A))] dp[0] = 0 for i in range(1,N): if i - 2>=0: dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2])) else: dp[i] =dp[i-1] + abs(A[i] - A[i-1]) print(dp) print(dp[len(A)-1])
p03160
s698287685
Wrong Answer
# EDPC A Frog 1 N = int(input()) H = list(map(int,input().split())) cost = [10001]*N cost[0] = 0 cost[1] = abs(H[1]-H[0]) for i in range(2,N): if cost[i] > cost[i-1]+abs(H[i]-H[i-1]): cost[i] = cost[i-1]+abs(H[i]-H[i-1]) if cost[i] > cost[i-2]+abs(H[i]-H[i-2]): cost[i] = cost[i-2]+abs(H[i]-H[i-2]) print(cost[N-1])
p03160
s101130538
Wrong Answer
n = input() heights = input()
p03160
s103304578
Wrong Answer
INF = 10 ** 5 + 10 def chmin(a, b): if a > b: a = b return a n = int(input()) H = list(map(int, input().split())) DP = [INF] * n DP[0] = 0 DP[1] = abs(H[1] - H[0]) for i in range(2, n): DP[i] = chmin(DP[i], DP[i-1] + abs(H[i] - H[i-1])) DP[i] = chmin(DP[i], DP[i-2] + abs(H[i] - H[i-2])) print(DP[-1])
p03160
s700587922
Wrong Answer
times = int(input())
p03160
s740384672
Wrong Answer
N = int(input()) h = [0] + list(map(int, input().split())) dp = [0] * (N+1) for i in range(2, N+1): dp[i] = dp[i-1] + abs(h[i] - h[i-1]) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print(dp[N])
p03160
s057111747
Wrong Answer
import numpy as np n = map(int, input()) h_list = [int(i) for i in input().split()] dp = np.zeros((len(h_list))) dp[1] = h_list[1]-h_list[0] for i in range(2,len(h_list)): temp1 = dp[i-1] + abs(h_list[i] - h_list[i-1]) temp2 = dp[i-2] + abs(h_list[i] - h_list[i-2]) dp[i] = min(temp1, temp2) print(dp[-1])
p03160
s285064747
Wrong Answer
n=int(input()) l=list(map(int,input().split())) dp=[0 for i in range(n)] dp[1]=l[1]-l[0] for i in range(2,n): dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2])) print(dp[n-1])
p03160
s084349598
Wrong Answer
N = int(input()) h = list(map(int, input().split())) dp = [10000000] * N dp[0] = 0 for i in range(N - 1): dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i])) if i < N - 2: dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i])) print(dp[N - 1])
p03160
s139294046
Wrong Answer
N = int(input()) A = list(map(int, input().split())) dp = [0 for _ in range(len(A))] dp[0] = 0 for i in range(1,N): if i - 2>=0: dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2])) else: dp[i] =dp[i-1] + abs(A[i] - A[i-1]) #print(dp) print(dp[len(A)-1])
p03160
s581146472
Wrong Answer
n = int(input()) h = list(map(int, input().split())) h = [0] + h dp = [0]*(n+1) dp[2] = abs(h[1] - h[2]) for i in range(2, n+1): dp[i] = min((dp[i-2] + abs(h[i-2]-h[i])), (dp[i-1] + abs(h[i-1]-h[i]))) print(dp[-1])
p03160
s087476173
Wrong Answer
n = int(input()) h = [0] + list(map(int, input().split())) dp =[0, h[0]] for i in range(2, n): dp += [min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))] print(dp[-1])
p03160
s385050209
Wrong Answer
n = int(input()) h = list(map(int, input().split())) l = [0, abs(h[-1] - h[-2])] + [-1] * (n-2) for i in range(2, n): l[i] = min(l[i-2]+abs(h[i-2]-h[i]), l[i-1]+abs(h[i-1]-h[i])) print(l[-1])
p03160
s951749165
Wrong Answer
n = int(input()) hlist = list(map(int, input().split())) dp = [0]*(n+1) for i in range(2, n+1): dp[i] = min(dp[i-1] + abs(hlist[i-2] - hlist[i-1]), dp[i-2] + abs(hlist[i-3] - hlist[i-1]) if i>2 else 1000) print(dp[n])
p03160
s527390333
Wrong Answer
N=int(input()) L=list(map(int,input().split())) S=[0]*100010 for i in range(N): S[i]=L[i] DP=[10*12]*100010 DP[0]=0 for i in range(N): if DP[i+1]>DP[i]+abs(S[i+1]-S[i]): DP[i+1]=DP[i]+abs(S[i+1]-S[i]) if DP[i+2]>DP[i]+abs(S[i+2]-S[i]): DP[i+2]=DP[i]+abs(S[i+2]-S[i]) print(DP[N-1])
p03160
s281163616
Wrong Answer
N = int(input()) h = list(map(int, input().split())) dp = [1000000] * N dp[0] = 0 for i in range(N): for j in range(1, 3): if i + j < N: dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j]) print(dp[N - 1])
p03160
s719897881
Wrong Answer
import numpy as np #N=int(input()) #h=list(map(int,input().split())) N=4 h=[10,30,40,20] dp=np.zeros(N) print(dp) dp[1]=abs(h[1]-h[0]) print(dp) for i in range(N-2): dp[i+2]=min(abs(h[i+2]-h[i])+dp[i],abs(h[i+2]-h[i+1])+dp[i+1]) print(dp) #dp[2]=min(h[2]-h[0],h[1]-h[0]) #total print(dp[-1])
p03160
s026566368
Wrong Answer
print(0)
p03160
s434044815
Wrong Answer
n = int(input()) h = list(map(int, input().split())) dp = [10 ** 4] * n dp[0] = 0 for i in range(1, n): dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1])) if i > 1: dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print(dp[n-1])
p03160
s352881547
Wrong Answer
n=int(input()) arr=list(map(int,input().split())) prev2 = 0 if n > 1: prev1 = abs(arr[0]-arr[1]) for i in range(3, n+1): step_1 = abs(arr[i-1]-arr[i-2]) + prev1 step_2 = abs(arr[i-1]-arr[i-3]) + prev2 x = min(step_1, step_2) prev1 = step_2 prev2 = x print(prev2)
p03160
s150011780
Wrong Answer
N = int(input()) h = list(map(int, input().split())) # N = 6 # h = [30, 10, 60, 10, 60, 50] dp = [0]*(N) print("ini dp", dp) for i in range(1, N): if i == 1: dp[1] = abs(h[1]-h[0]) print("ini dp 1", dp) else: dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])) print("ini dp 2", dp) print(dp[-1])
p03160
s071980431
Wrong Answer
n=int(input()) h=list(map(int,input().split())) res=[-1]*n res[0]=h[0] res[1]=abs(h[0]-h[1]) for i in range(2,n): res[i]=min(abs(h[i-1]-h[i])+res[i-1],abs(h[i-2]-h[i])+res[i-2]) print(res[-1])
p03160
s630892288
Wrong Answer
n=int(input()) a=list(map(int,input().split())) dp=[0 for i in range(n)] dp[0]=a[0] dp[1]=abs(a[0]-a[1]) for i in range(n-2): dp[i+2]=abs(dp[i]-dp[i+2]) dp[i+1]=abs(min(dp[i+1],dp[i]+abs(a[i+1]-a[i]))) if(n>2): dp[-1]=min(dp[-2]+abs(a[-1]-a[-2]),dp[-3]+abs(a[-3]-a[-2])) print(dp[-1])
p03160
s168821226
Wrong Answer
N = int(input()) h = list(map(int, input().split())) dp = [] dp.append(0) dp.append(abs(h[1]-h[0])) for i in range(2,N): t1 = dp[i - 2] + abs(h[i] - h[i - 2]) t2 = dp[i - 1] + abs(h[i] - h[i - 1]) dp.append(min(t1, t2))
p03160
s245961016
Wrong Answer
n=int(input()) h=list(map(int, input().split())) dp=[10**5 for i in range(n)] dp[0]=0 for i in range(n): if i+1<n:dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i])) if i+2<n:dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i])) print(dp[n-1])
p03160
s719689503
Wrong Answer
def hoge(): dp =[0] * (n + 1) dp[0] = 0 dp[1] = abs(h_list[1] - h_list[0]) for i in range(1, n): dp[i + 1] = min(dp[i - 2] + abs(h_list[i - 2] - h_list[i]), dp[i - 1] + abs(h_list[i - 1] - h_list[i])) return dp[n] def solve(): global n, h_list n = int(input()) h_list = list(map(int, input().split())) ans = hoge() print(ans) return 0 if __name__ == "__main__": solve()
p03160
s781926420
Wrong Answer
N=int(input()) h=input().split() i = N - 1 sum = 0 while i > 1: if abs(int(h[i]) - int(h[i-1])) < abs(int(h[i]) - int(h[i-2])): sum += abs(int(h[i]) - int(h[i-1])) i -= 1 else: sum += abs(int(h[i]) - int(h[i-2])) i -= 2 if i == 1: sum += abs(int(h[1]) - int(h[0])) print(sum)
p03160
s167435598
Wrong Answer
n=int(input()) h=list(map(int,input().split())) ans=0 temp=[0]*n temp[0]=0 temp1=abs(h[1]-h[0]) for i in range(2,n): temp[i]=min(temp[i-1]+abs(h[i]-h[i-1]),temp[i-2]+abs(h[i]-h[i-2])) print(temp[n-1])
p03160
s440055889
Wrong Answer
n=int(input()) k=2 l=list(map(int,input().split())) ans=[0,abs(l[1]-l[0])] for i in range(2,n): m=10**4+1 c=1 while c<min(k+1,i+1): m=min(abs(l[i]-l[i-c])+ans[-c],m) c+=1 ans.append(m) # print(ans) print(ans[-1])
p03160
s806890025
Wrong Answer
N = int(input()) h = [int(i) for i in input().split()] dp = [10**5 for _ in range(N)] dp[0] = 0 for i in range(N-1): dp[i+1] = min(dp[i+1],dp[i] + abs(h[i+1] -h[i])) if i+2 < N: dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] -h[i])) print(dp[-1])
p03160
s181040944
Wrong Answer
N = int(input()) footing = list(map(int, input().split())) dp = [10 ** 6] * N dp[0] = 0 # give for i in range(N-1): if dp[i+1] > dp[i] + abs(footing[i+1] - footing[i]): dp[i+1] = dp[i] + abs(footing[i+1] - footing[i]) if i < N-2: if dp[i+2] > dp[i] + abs(footing[i+2] - footing[i]): dp[i+2] = dp[i] + abs(footing[i+2] - footing[i]) print(dp[N-1])
p03160
s043849315
Wrong Answer
def chmin(DP,b,i): if (DP[i]> b): DP[i] = b return True return False N = int(input()) H = [i for i in map(int,input().split())] dp = [10**5 for i in range(N)] dp[0] = 0 for i in range(1,N): chmin(dp,dp[i-1]+abs(H[i]-H[i-1]),i) if i > 1: chmin(dp,dp[i-2]+abs(H[i]-H[i-2]),i) print(dp[-1])
p03160
s113999513
Wrong Answer
print('hello')
p03160
s117564214
Wrong Answer
n=int(input()) rec=list(map(int,input().split())) s=[rec[0],abs(rec[1]-rec[0])] for i in range(2,n): total2=abs(rec[i]-rec[i-2])+s[i-2] total1=abs(rec[i]-rec[i-1])+s[i-1] s.append(min(total2,total1)) print(s[-1])
p03160
s274904879
Wrong Answer
N = int(input()) h = list(map(int,input().split())) A = [float('inf')] * (N) A[0] = 0 for i in range(N-2): p = A[i] + abs(h[i+1] - h[i]) q = A[i] + abs(h[i+2] - h[i]) if p < A[i+1]: A[i+1] = p if q < A[i+2]: A[i+2] = q print(A[N-1])
p03160
s517783599
Wrong Answer
N = int(input()) H = list(map(int,input().split())) # DPテーブル DP = [float('inf')]*N # 初期条件 DP[0] = 0 DP[1] = abs(H[1] - H[0]) for i in range(2,N): one_step = DP[i-1] + abs(H[i]-H[i-1]) two_step = DP[i-2] + abs(H[i]-H[i-2]) DP[i] = min(one_step,two_step) print(DP) print(DP[N-1])
p03160
s867597187
Wrong Answer
def solution(h): n = len(h) if n == 1: return 0 elif n == 2: return abs(h[1]-h[0]) dp = [0]*(n) 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) return dp[n-1] N = int(input()) h = list(map(int,input().split())) res = solution(h) print(res,end="")
p03160
s999546334
Wrong Answer
N, *h = map( int, open(0).read().split()) D = [0] + [ abs( h[1] - h[0])] k = 0 for i in range( 1, N - 1 ): k = min( D[ 0 ] + abs( h[ i + 1 ] - h[ i - 1 ]), D[ 1 ] + abs( h[ i + 1 ] - h[ i ])) D[ 0 ], D[ 1 ] = D[ 1 ], k print( k )
p03160
s501078090
Wrong Answer
N = int(input()) h = [int(x) for x in input().split()] dp = [1000000 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], dp[i-1] + abs(h[i] - h[i-1])) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print(dp[-1])
p03160
s368991372
Wrong Answer
n = int(input()) h = list(map(int,input().split())) dp = [10 ** 5 for i in range(n)] dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(n-2): dp[i+2] = min(dp[i] + abs(h[i+2] - h[i]), dp[i+1] + abs(h[i+1] - h[i])) print(dp)
p03160
s807616527
Wrong Answer
n=int(input()) h=list(map(int,input().split())) h.insert(0,0) dp=[0 for i in range(n+1)] for i in range(2,n+1): dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])) print(dp[n])
p03160
s772997394
Wrong Answer
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) n = int(input()) h = [0] + list(map(int, input().split())) dp = [10 ** 7] + [10 ** 7] * n dp[1] = 0 def chmin(dp_table, index, value): if dp_table[index] > value: dp_table[index] = value for i in range(2, n+1): chmin(dp, i, dp[i-1] + abs(h[i] - h[i-1])) chmin(dp, i, dp[i-2] + abs(h[i] - h[i-2])) print(dp[n])
p03160
s404671391
Wrong Answer
dp = [1001 for i in range(100002)] n = int(input()) hs = list(map(int, input().split())) dp[0] = 0 for i in range(1, n): dp[i] = min(dp[i], dp[i-1] + abs(hs[i-1] - hs[i])) if i > 1 : dp[i] = min(dp[i], dp[i-2] + abs(hs[i-2] - hs[i])) print(dp[n-1])
p03160
s292696550
Wrong Answer
n = int(input()) h = list(map(int,input().split())) cost = [0]*n for i in range(1,n): cost[i] = cost[i-1] + abs(h[i]-h[i-1]) if i > 1: if cost[i] > cost[i-1] + abs(h[i]-h[i-2]): cost[i] = cost[i-2] + abs(h[i]-h[i-2]) print(cost[n-1])
p03160
s178059906
Wrong Answer
n = int(input()) h = list(map(int, input().split())) h.append(1000000007) dp = [h[0]] count = 0 while count < n - 1: sgst_1 = abs(h[count + 1] - h[count]) sgst_2 = abs(h[count + 2] - h[count]) if sgst_1 <= sgst_2: dp.append(sgst_1) count += 1 else: dp.append(sgst_2) count += 2 print(dp[-1])
p03160
s262815306
Wrong Answer
n = int(input()) h = list(map(int, input().split())) dp = [10 ** 4] * n dp[0] = 0 for i in range(1, n): dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1])) if i > 1: dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print(dp[-1])
p03160
s029058496
Wrong Answer
import math n = int(input()) list_ = list(map(int, input().split())) cost_list = [math.inf for _ in range(n)] cost_list[0]=0 cost_list[1]=list_[1]-list_[0] for i in range(2,n): one = cost_list[i-1] + abs(list_[i]-list_[i-1]) two = cost_list[i-2] + abs(list_[i]-list_[i-2]) cost_list[i]=min(one,two,) print(cost_list[-1])
p03160
s466385438
Wrong Answer
N = int(input()) h = list(map(int, input().split())) a, b = 0, abs(h[-1] - h[-2]) for n in range(0, N - 2): a, b = b, min(b + abs(h[-(n + 3)] - h[-(n + 2)]), a + abs(h[-(n + 3)] - h[-(n + 1)])) print(a)
p03160
s897026173
Wrong Answer
N = int(input()) h = list(map(int,input().split())) DP = [10**9]*N DP[0] = 0 #DP[1] = abs(h[1]-h[0]) DP[1] = min(DP[1],DP[0]+abs(h[0]-h[1])) for i in range(N-2): DP[i+1] = min(DP[i+1],DP[i]+abs(h[i]-h[i+1])) DP[i+2] = min(DP[i+2],DP[i]+abs(h[i]-h[i+2])) print(DP[-1])
p03160
s221140400
Wrong Answer
N = int(input()) h = list(map(int, input().split())) def chmin(a, b): min = a if a > b: min = b return min h_inf = 10 ** 5 dp = [h_inf] * 10 ** 6 dp[0] = 0 for i in range(10**6): h.append(10**5) for i in range(N): dp[i+1] = chmin(dp[i+1], dp[i]+abs(h[i]-h[i+1])) dp[i+2] = chmin(dp[i+2], dp[i]+abs(h[i]-h[i+2])) print(dp[N-1])
p03160
s375361305
Wrong Answer
# -*- coding: utf-8 -*- """ Created on Sat May 2 00:21:08 2020 @author: Kanaru Sato """ N = int(input()) h = list(map(int, input().split())) memo = [100000000000]*N #topdown def cost(n): if n == 0: return 0 elif n == 1: return abs(h[1]-h[0]) elif memo[n]: return memo[n] else: memo[n] = min(cost(n-2)+abs(h[n]-h[n-2]),cost(n-1)+abs(h[n]-h[n-1])) return memo[n] print(cost(N-1))
p03160
s144752043
Wrong Answer
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n,*H = list(map(int,read().split())) h = [0] h.extend(H) h.append(0) dp = [100] * (n+5) dp[1] = 0 for i in range(1,n): dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i])) dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i])) print(dp[n])
p03160
s515314499
Wrong Answer
N = int(input()) h = list(map(int,input().split())) DP = [10**9]*N DP[0] = 0 #DP[1] = abs(h[1]-h[0]) DP[1] = min(DP[1],DP[0]+abs(h[0]-h[1])) for i in range(N-2): DP[i+1] = min(DP[i+1],DP[i]+abs(h[i]-h[i+1])) DP[i+2] = min(DP[i+2],DP[i]+abs(h[i]-h[i+2])) print(DP)
p03160
s488918118
Wrong Answer
import numpy as np N=int(input()) K=2 #N,K=map(int,input().split()) H=list(map(int,input().split())) dp=np.empty(N,dtype=int) dp[0]=0 for i in range(1,N): a=10**5 for j in range(1,min(K,i)+1): a=min(a,dp[i-j]+abs(H[i]-H[i-j])) dp[i]=a print(dp[-1])
p03160
s579747885
Wrong Answer
n = int(input()) pedras = list(map(int,input().split())) dp = [0] * n dp[0] = 0 dp[1] = abs(pedras[0] - pedras[1]) for i in range(2,n): custo1 = dp[i-1] + abs(pedras[i-1] - pedras[i]) custo2 = dp[i-2] + abs(pedras[i-2] - pedras[i]) dp[i] = min(custo1,custo2)
p03160
s654153949
Wrong Answer
N=int(input()) h_array=input().split() dp=[0]*N def f(a,b): return abs(int(h_array[a])-int(h_array[b])) dp[0]=0 dp[1]=abs(int(h_array[0])-int(h_array[1])) for n in range(2,N): dp[n] = dp[n-1]+f(n-1,n) if f(n-1,n)<f(n-2,n) else dp[n-2]+f(n-2,n) print(dp[-1])
p03160
s129047071
Wrong Answer
n = int(input()) h = list(map(int,input().split())) dp = [10 ** 4 for i in range(n)] dp[0] = 0 for i in range(n): if i <= n - 2: val1 = dp[i] + abs(h[i+1] - h[i]) if val1 < dp[i+1]: dp[i+1] = val1 if i <= n - 3: val2 = dp[i] + abs(h[i+2] - h[i]) if val2 < dp[i+2]: dp[i+2] = val2 print(dp[-1])
p03160
s846334685
Wrong Answer
n = int(input()) h = [int(i) for i in input().split()] dp = [0,h[1]-h[0]] for i in range(2,n): dp.append(min(dp[-2] + abs(h[i] - h[i-2]),dp[-1] + abs(h[i] - h[i-1]))) print(dp[n-1])
p03160
s507963517
Wrong Answer
n = int(input()) h = list(map(int, input().split())) dp = [float('inf')] * n dp[0] = 0 dp[1] = abs(h[0] - h[1]) for i in range(2, n - 1): dp[i] = max((dp[i - 2] + abs(h[i - 2] - h[i])), (dp[i - 1] + abs(h[i - 1] - h[i]))) print(dp[n - 1])
p03160
s570499261
Wrong Answer
N = int(input()); salto = [int(i) for i in input().split()]; Costo = [float('inf')]*(N - 2)+[0, abs(salto[1] - salto[0])] ; for i in range(2, N): Costo[i] = min(Costo[i - 2] + abs(salto[i] - salto[i - 2]), Costo[i - 1] + abs(salto[i] - salto[i - 1])); print(Costo[N - 1]);
p03160
s577271844
Wrong Answer
n = int(input()) hs = [int(c) for c in input().split()] dp = [0] * n dp[0] = 0 dp[1] = abs(hs[0] - hs[1]) for i in range(2, n): dp[i] = min(dp[i-1] + abs(hs[i-1] - hs[i]), dp[i-2] + abs(hs[i-2] - hs[i])) print(dp[-1])
p03160
s764133158
Wrong Answer
INF = 10 ** 4 + 10 def chmin(a, b): if a > b: a = b return a n = int(input()) H = list(map(int, input().split())) DP = [INF] * n DP[0] = 0 DP[1] = abs(H[1] - H[0]) for i in range(2, n): DP[i] = chmin(DP[i], DP[i-1] + abs(H[i] - H[i-1])) DP[i] = chmin(DP[i], DP[i-2] + abs(H[i] - H[i-2])) print(DP[-1])
p03160
s503669709
Wrong Answer
n=int(input()) h=list(map(int,input().split())) dp=[0]*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[0])) print(dp[n-1])
p03160
s633408559
Wrong Answer
N = int(input()) h = list(map(int, input().split())) ans = [100000000] * N ans[0] = 0 for i in range(N-1): ans[i+1] = min(ans[i+1], ans[i] + abs(h[i] - h[i+1])) if i + 2 > N - 1: continue ans[i+2] = min(ans[i+2], ans[i] + abs(h[i] - h[i+2])) print(ans[-1])
p03160
s076684453
Wrong Answer
N = int(input()) h = input().split() h = [int(i) for i in h] dp = [10**7] * N dp[0] = 0 for i in range(1, N): dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i-1])) if i > 1: dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i-2])) print(dp[N-1])
p03160
s313247702
Wrong Answer
def chmin(a, b): if a > b: return b else: return a def main(): dp = [1e8]*100010 hs = [0]*100010 N = int(input()) hs[:N] = map(int, input().split()) dp[0] = 0 for i in range(N): dp[i+1] = chmin(dp[i+1], dp[i]+abs(hs[i+1]-hs[i])) dp[i+2] = chmin(dp[i+2], dp[i]+abs(hs[i+2]-hs[i])) print(dp[N-1]) return if __name__ == '__main__': main()
p03160
s657506202
Wrong Answer
def main(): n = int(input()) costs = list(map(int, input().split())) if n==1: return 0 # each cur represents minimum cost needed to reach the step two_before = 0 one_before = costs[1] - costs[0] for step in range(2, n): two_before, one_before = one_before, min(one_before + abs(costs[step] - costs[step-1]), two_before + abs(costs[step] - costs[step - 2])) return one_before print(main())
p03160
s459440401
Wrong Answer
n = int(input()) h = list(map(int, input().split())) inf = 10**7 dp = [inf] * (n+1) dp[1] = 0 for i in range(1, n): if i+1 <= n: dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1-1]-h[i-1])) if i+2 <= n: dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2-1]-h[i-1])) print(dp[n])
p03160
s558143782
Wrong Answer
N = int(input()) h = list(map(int, input().split())) dp = [float('inf') for i in range(N)] dp[0] = 0 dp[1] = 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-1])) print(dp[N-1])
p03160
s925736322
Wrong Answer
N = int(input()) h = list(map(int,input().split())) dp = [float('inf')]*N dp[0] = 0 dp[1] = 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])
p03160
s797667335
Wrong Answer
n = int(input()) h = list(map(int, input().split())) a = [0] * n a[1] = abs(h[0] - h[1]) for i in range(2, n): w1 = a[i-1] + abs(h[i-1] - h[i]) w2 = a[i-2] + abs(h[i-2] - a[i]) a[i] = min(w1, w2) print(a[n-1])
p03160
s094065920
Wrong Answer
# n,k = map(int, input().split()) n = int(input()) h = list(map(int,input().split())) dp = [0] * n dp[0] = 0 dp[1] = h[1] - h[0] for i in range(2,n): dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]) # dp[2] = min((h[2] - h[1])+dp[1], (h[2]-h[0])+dp[0]) # dp[3] = min((h[3] - h[2])+dp[2], (h[3]-h[1])+dp[1]) print(dp[-1])
p03160
s004604968
Wrong Answer
N = int(input()) A = list(map(int, input().split())) inf = float("inf") dp = [inf] * N dp[0] = 0 dp[1] = abs(A[0]-A[1]) for i in range(2, N): dp[i] = min(dp[i-1]+abs(A[i]-A[i-2]),dp[i-2]+abs(A[i]-A[i-2])) print(dp[N-1])
p03160
s447236036
Wrong Answer
N = int(input()) h = list(map(int, input().split())) ans = [1000000] * N ans[0] = 0 for i in range(N-1): ans[i+1] = min(ans[i+1], ans[i] + abs(h[i] - h[i+1])) if i + 2 > N - 1: continue ans[i+2] = min(ans[i+2], ans[i] + abs(h[i] - h[i+2])) print(ans[-1])
p03160
s678048972
Wrong Answer
import sys n = int(input()) h = list(map(int,input().split())) inf = float("inf") dp = [inf]*(n+1) if n == 2: print(abs(h[1]-h[0])) sys.exit() dp[1] = abs(h[1]-h[0]) dp[2] = min(abs(h[2]-h[1]), abs(h[2]-h[0])) for i in range(3,n): dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]) print(dp[n-1])
p03160
s691925733
Wrong Answer
import numpy as np N = int(input()) h = [0] + list(map(int, input().split())) dp = np.zeros(N+1, dtype=np.int32) for i in range(2, N+1): dp[i] = dp[i-1] + abs(h[i] - h[i-1]) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2])) print(dp[N])
p03160
s603143509
Wrong Answer
N = int(input()) h = [int(i) for i in input().split()] dp = [10001]*N dp[0] = 0 dp[1] = abs(h[0]-h[1]) def chmin(i, b): if dp[i] > b: dp[i] = b for i in range(2,N): chmin(i, dp[i-1] + abs(h[i] - h[i-1])) chmin(i, dp[i-2] + abs(h[i] - h[i-2])) print(dp[-1])
p03160
s080997328
Wrong Answer
n = int(input()) hlis = list(map(int, input().split())) dp = [0] + [abs(hlis[0] - hlis[1])] + [float('inf')]*(n-2) for i in range(n-2): one = abs(hlis[i]-hlis[i+1]) two = abs(hlis[i]-hlis[i+2]) dp[i+1] = min(dp[i]+one, dp[i+1]) dp[i+2] = min(dp[i]+two, dp[i+2]) print(dp[n-1])
p03160
s060055892
Wrong Answer
N = int(input()) h = [0] + list(map(int, input().split())) dp = [None for _ in range(N+1)] dp[0] = 0 dp[1] = 0 for i in range(2, N+1): one = dp[i-1] + abs(h[i]-h[i-1]) two = dp[i-2] + abs(h[i]-h[i-2]) dp[i] = min(one, two) print(dp[N])
p03160
s475777848
Wrong Answer
def frog_jump(n:int, stones)->int: dp = [float('inf')] * n jumps = (1, 2) dp[0] = 0 for idx in range(len(dp)): for jump in jumps: if idx+jump < len(dp): dp[idx+jump] = min(dp[idx]+abs(stones[idx+jump]-stones[idx]), dp[idx+jump]) return dp[-1] frog_jump(6, [30, 10, 60, 10, 60, 50])
p03160
s516149873
Wrong Answer
arr = [10,30,40,20] dp = [-1 for i in range(len(arr))] dp[0] = 0 dp[1] = abs(arr[1]-arr[0]) for i in range(2, len(arr)): dp[i] = min(dp[i-2] + abs(arr[i]-arr[i-2]), dp[i-1] + abs(arr[i]-arr[i-1])) print(dp[-1])