Problem p03162 (python)

Fixed submission:
#C
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(3)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    dp[0][i+1] =  chmax(dp[1][i]+abc[i+1][0],dp[2][i]+abc[i+1][0])
    dp[1][i+1] =  chmax(dp[0][i]+abc[i+1][1],dp[2][i]+abc[i+1][1])
    dp[2][i+1] =  chmax(dp[1][i]+abc[i+1][2],dp[0][i]+abc[i+1][2])


ans = chmax(dp[0][N-1],dp[1][N-1])
ans = chmax(ans,dp[2][N-1])
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    dp[0][i+1] =  chmax(dp[1][i]+abc[i+1][0],dp[2][i]+abc[i+1][0])
    dp[1][i+1] =  chmax(dp[0][i]+abc[i+1][1],dp[2][i]+abc[i+1][1])
    dp[2][i+1] =  chmax(dp[1][i]+abc[i+1][2],dp[0][i]+abc[i+1][2])


ans = chmax(dp[0][N-1],dp[1][N-1])
ans = chmax(ans,dp[2][N-1])
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[j][i]+abc[i+1][k])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[j][i]+abc[i+1][k])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)
print(dp)

Buggy submission (verdict: Runtime Error):
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[j][i]+abc[i+1][k])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)

Buggy submission (verdict: Runtime Error):
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[j][i]+abc[i+1][k])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)
print(dp)

Buggy submission (verdict: Runtime Error):
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N)] #i日目の活動をa,b,cで終えた幸福度のmax
dp[0][0] = abc[0][0]
dp[1][0] = abc[0][1]
dp[2][0] = abc[0][2]

def chmax(a,b):
    if a < b:
        return b
    else:
        return a 

for i in range(N-1):
    for k in range(3):
        for j in range(3):
            if j == k:
                pass
            else:
                dp[k][i+1] =  chmax(dp[k][i+1],dp[k][i]+abc[i+1][j])

ans = 0
for i in range(3):
    ans = chmax(ans,dp[i][N-1])
    
print(ans)