結果

問題 No.1199 お菓子配り-2
ユーザー donutholedonuthole
提出日時 2020-08-28 22:26:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 400 ms / 1,000 ms
コード長 1,388 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 51,712 KB
最終ジャッジ日時 2024-04-26 15:00:57
合計ジャッジ時間 14,901 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,520 KB
testcase_01 AC 30 ms
11,520 KB
testcase_02 AC 29 ms
11,392 KB
testcase_03 AC 117 ms
21,376 KB
testcase_04 AC 248 ms
36,864 KB
testcase_05 AC 36 ms
12,288 KB
testcase_06 AC 41 ms
12,800 KB
testcase_07 AC 133 ms
23,680 KB
testcase_08 AC 173 ms
28,288 KB
testcase_09 AC 120 ms
21,504 KB
testcase_10 AC 49 ms
13,824 KB
testcase_11 AC 94 ms
19,328 KB
testcase_12 AC 94 ms
19,072 KB
testcase_13 AC 51 ms
13,952 KB
testcase_14 AC 48 ms
13,568 KB
testcase_15 AC 48 ms
13,056 KB
testcase_16 AC 167 ms
27,392 KB
testcase_17 AC 102 ms
19,200 KB
testcase_18 AC 183 ms
29,184 KB
testcase_19 AC 67 ms
15,744 KB
testcase_20 AC 301 ms
42,112 KB
testcase_21 AC 195 ms
30,720 KB
testcase_22 AC 112 ms
21,120 KB
testcase_23 AC 153 ms
25,344 KB
testcase_24 AC 207 ms
30,976 KB
testcase_25 AC 55 ms
14,336 KB
testcase_26 AC 221 ms
32,896 KB
testcase_27 AC 187 ms
29,056 KB
testcase_28 AC 373 ms
51,584 KB
testcase_29 AC 371 ms
51,584 KB
testcase_30 AC 377 ms
51,712 KB
testcase_31 AC 391 ms
51,712 KB
testcase_32 AC 375 ms
51,712 KB
testcase_33 AC 365 ms
51,712 KB
testcase_34 AC 373 ms
51,712 KB
testcase_35 AC 376 ms
51,712 KB
testcase_36 AC 394 ms
51,712 KB
testcase_37 AC 381 ms
51,712 KB
testcase_38 AC 369 ms
51,712 KB
testcase_39 AC 377 ms
51,712 KB
testcase_40 AC 370 ms
51,584 KB
testcase_41 AC 373 ms
51,712 KB
testcase_42 AC 373 ms
51,712 KB
testcase_43 AC 373 ms
51,712 KB
testcase_44 AC 373 ms
51,712 KB
testcase_45 AC 374 ms
51,712 KB
testcase_46 AC 400 ms
51,712 KB
testcase_47 AC 378 ms
51,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import collections
import bisect
import itertools
import decimal

# import numpy as np

# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n, m = ns()
    mat = [na() for _ in range(n)]

    res = []
    for i in range(n):
        tmp = 0
        for j in range(m):
            tmp += mat[i][j]
        res.append(tmp)

    start = -1
    for i in range(1, n):
        if res[i] < res[i - 1]:
            start = i-1
            break
    if start == -1:
        print(res[-1])
        exit(0)

    ans = res[start]
    minimum = res[start]
    flg = 0  # 0:kudari 1:nobori
    for i in range(start + 1, n):
        if flg == 0:
            if res[i] <= minimum:
                minimum = res[i]
            else:
                flg = 1
        else:
            if res[i] >= res[i - 1]:
                continue
            else:
                ans += res[i - 1] - minimum
                minimum = res[i]
                flg = 0

    if flg == 1:
        ans += res[-1] - minimum
    print(ans)

if __name__ == '__main__':
    main()
0