Problem p03162 (python)

Fixed submission:
N = int(input())

vacation = []

for i in range(N):
    a,b,c = map(int, input().split())

    vacation.append([a,b,c])

dp = []*N

for i in range(N):
    dp.append([0, 0, 0])

dp[0][0]=vacation[0][0]
dp[0][1]=vacation[0][1]
dp[0][2]=vacation[0][2]

for i in range(0, N-1, 1):

    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            dp[i+1][j] = max(dp[i+1][j], dp[i][k]+vacation[i+1][j])

print(max(dp[N-1]))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000)

N = int(input())
D = []
dp = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])
    dp.append([-1]*3)

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if dp[n][activity]!=-1:
        return dp[n][activity]
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
            dp[n][activity] = ans
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    dp[n][activity] = ans
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2000000)

N = int(input())
D = []
dp = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])
    dp.append([-1]*3)

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if dp[n][activity]!=-1:
        return dp[n][activity]
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
            dp[n][activity] = ans
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    dp[n][activity] = ans
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

N = int(input())
D = []
dp = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])
    dp.append([-1]*3)

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if dp[n][activity]!=-1:
        return dp[n][activity]
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    dp[n][activity] = ans
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

N = int(input())
D = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
D = []
for _ in range(N):
    a,b,c = map(int, input().split())
    D.append([a,b,c])

def dfs(n, activity):#n日目にactivityを選んだ場合の最大幸福
    if n==1:
        ans = 0
        for i in range(3):
            if i!=activity:
                ans = max(ans, D[1][activity]+D[0][i])
        return ans
    ans = 0
    for i in range(3):
        if i!=activity:
            ans =max(ans, D[n][activity]+dfs(n-1, i))
    return ans
ans = 0
for i in range(3):
    ans = max(ans, dfs(N-1, i))
print(ans)