Problem p03162 (python)

Fixed submission:
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template

def retmax(a, b):
    if a > b:
        return a
    else:
        return b

def main():
    n = int(input())
    a = [list(map(int, input().split())) for _ in range(n)]

    dp = np.zeros([3, n+1])

    for i, a_l in enumerate(a):
        for j in range(3):
            for k in range(3):
                if j != k:
                    dp[k, i+1] = retmax(dp[k, i+1], dp[j, i] + a_l[k])

    print(int(np.max(dp[:, n], axis=0)))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [list(map(int, input().split())) for _ in input().split()]

x, y, z = 0, 0, 0
for a, b, c in h:
    x, y, z = max(y,z) + a, max(x,z) + b, max(x,y) + c

print(max(x, y, z))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

a, b, c = 0, 0, 0
for x, y, z in a:
    a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z

print(max(a, b, c))

Buggy submission (verdict: Runtime Error):
import numpy as np  

n = int(input())
h = [list(map(int, input().split())) for _ in range(n)]

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, k] = max(dp[i+1, k], dp[i, j] + val[k])

print(int(np.max(dp[n, :], axis=1)))

Buggy submission (verdict: Runtime Error):
import numpy as np  

n = int(input())
h = [list(map(int, input().split())) for _ in range(n)]

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, k] = max(dp[i+1, k], dp[i, j] + val[k])

print(int(np.max(dp[n, :], axis=1)))

Buggy submission (verdict: Runtime Error):
import numpy as np  

n = int(input())
h = [list(map(int, input().split())) for _ in range(n)]

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, j] = max(dp[i+1, j], dp[i, j] + val[k])

print(int(np.max(dp[n, :], axis=1)))

Buggy submission (verdict: Runtime Error):
import numpy as np  

n = int(input())
h = [list(map(int, input().split()) for _ in range(n)]

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, j] = max(dp[i+1, j], dp[i, j] + val[k])

print(np.max(dp[n, :], axis=1))

Buggy submission (verdict: Runtime Error):

n = int(input())
h = [list(map(int, input().split()) for _ in range(n)]

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, j] = max(dp[i+1, j], dp[i, j] + val[k])

print(np.max(dp[n, :], axis=1))

Buggy submission (verdict: Runtime Error):

n = int(input())
h = [list(map(int, input().split()) for _ in range(n)]

dp = np.zeros([n+1, 3])

for i, val in enumerate(h):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1, j] = np.max(dp[i+1, j], dp[i, j] + val[k])

print(np.max(dp[n, :], axis=1))

Buggy submission (verdict: Runtime Error):
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


def main():
    n = int(input())
    abc = [list(map(int, input().split())) for _ in range(n)]

    dp = [ [0, 0, 0] for _ in range(n) ]

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

    ans = 0
    for i in range(3):
        ans = max(ans, dp[n][i])

    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


def main():
    n = int(input())
    abc = [list(map(int, input().split())) for _ in range(n)]

    dp = [ [0, 0, 0] for _ in range(n) ]

    dp[0] = abc[0]

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

    ans = 0
    for i in range(3):
        ans = max(ans, dp[n][i])

    print(ans)


if __name__ == "__main__":
    main()