結果

問題 No.1199 お菓子配り-2
ユーザー mkawa2mkawa2
提出日時 2021-07-16 09:22:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 318 ms / 1,000 ms
コード長 1,075 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 11,028 KB
実行使用メモリ 48,764 KB
最終ジャッジ日時 2023-09-19 05:41:56
合計ジャッジ時間 20,817 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,376 KB
testcase_01 AC 16 ms
8,356 KB
testcase_02 AC 17 ms
8,256 KB
testcase_03 AC 93 ms
18,188 KB
testcase_04 AC 213 ms
33,940 KB
testcase_05 AC 24 ms
9,028 KB
testcase_06 AC 26 ms
9,820 KB
testcase_07 AC 109 ms
20,468 KB
testcase_08 AC 142 ms
25,128 KB
testcase_09 AC 93 ms
18,416 KB
testcase_10 AC 35 ms
10,660 KB
testcase_11 AC 75 ms
16,132 KB
testcase_12 AC 71 ms
15,856 KB
testcase_13 AC 36 ms
10,852 KB
testcase_14 AC 33 ms
10,224 KB
testcase_15 AC 29 ms
9,928 KB
testcase_16 AC 138 ms
24,284 KB
testcase_17 AC 77 ms
16,044 KB
testcase_18 AC 148 ms
26,040 KB
testcase_19 AC 50 ms
12,556 KB
testcase_20 AC 244 ms
38,844 KB
testcase_21 AC 163 ms
27,552 KB
testcase_22 AC 94 ms
17,992 KB
testcase_23 AC 126 ms
22,288 KB
testcase_24 AC 164 ms
28,064 KB
testcase_25 AC 37 ms
11,100 KB
testcase_26 AC 178 ms
30,020 KB
testcase_27 AC 145 ms
26,028 KB
testcase_28 AC 314 ms
48,752 KB
testcase_29 AC 310 ms
48,764 KB
testcase_30 AC 315 ms
48,440 KB
testcase_31 AC 314 ms
48,548 KB
testcase_32 AC 317 ms
48,476 KB
testcase_33 AC 313 ms
48,452 KB
testcase_34 AC 312 ms
48,420 KB
testcase_35 AC 314 ms
48,552 KB
testcase_36 AC 312 ms
48,352 KB
testcase_37 AC 314 ms
48,568 KB
testcase_38 AC 311 ms
48,516 KB
testcase_39 AC 312 ms
48,440 KB
testcase_40 AC 316 ms
48,636 KB
testcase_41 AC 314 ms
48,416 KB
testcase_42 AC 318 ms
48,448 KB
testcase_43 AC 312 ms
48,432 KB
testcase_44 AC 314 ms
48,420 KB
testcase_45 AC 313 ms
48,436 KB
testcase_46 AC 313 ms
48,536 KB
testcase_47 AC 312 ms
48,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

n, m = LI()
aa = LLI(n)
ss = []
for row in aa:
    ss.append(sum(row))

def chmax(i, j, val):
    if val > dp[i][j]: dp[i][j] = val

dp = [[-inf]*2 for _ in range(n+1)]
dp[0][1] = 0
for i in range(n):
    for j in range(2):
        pre = dp[i][j]
        if pre==-inf:continue
        if j:
            chmax(i+1, 0, pre+ss[i])
            chmax(i+1, 1, pre)
        else:
            chmax(i+1, 1, pre-ss[i])
            chmax(i+1, 0, pre)

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