LoginSignup
0
0

More than 3 years have passed since last update.

yukicoder contest 263 参戦記

Last updated at Posted at 2020-08-28

yukicoder contest 263 参戦記

A 1198 お菓子配り-1

突破できず. どこが★1だよというツッコミどころしかない. N≤1025 で int64 に収まらず、これだけでも★1ではないよなと思った. まあ、Python は int64 の値域を超えてても平気であるが. 数学問題なんだろうなあとは思ったけど、やっぱり解けなかった.

N = int(input())

if N == 1 or N == 4 or N % 4 == 2:
    print(-1)
else:
    print(1)

B 1199 お菓子配り-2

素直な DP. 偶数個取った時の最大値、奇数個取った時の最大値を更新してばいいだけ.

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)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0