I couldn't break through. There was nothing but a tsukkomi saying where ★ 1 was. N ≤ 10 25 </ sup> did not fit in int64, and I thought that this alone was not ★ 1. Well, Python is int64. It's okay to go beyond the range. I thought it was a math problem, but I couldn't solve it.
N = int(input())
if N == 1 or N == 4 or N % 4 == 2:
print(-1)
else:
print(1)
Straightforward DP. All you have to do is update the maximum value when you take an even number and the maximum value when you take an odd number.
from sys import stdin
readline = stdin.readline
N, M = map(int, readline().split())
odd, even = 0, 0
for _ in range(N):
s = sum(map(int, readline().split()))
t = odd
odd = max(odd, even + s)
even = max(even, t - s)
print(odd)
Recommended Posts