結果

問題 No.1199 お菓子配り-2
ユーザー donutholedonuthole
提出日時 2020-08-28 22:26:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 342 ms / 1,000 ms
コード長 1,388 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 11,136 KB
実行使用メモリ 49,628 KB
最終ジャッジ日時 2023-08-08 22:50:11
合計ジャッジ時間 13,762 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
9,016 KB
testcase_01 AC 21 ms
9,096 KB
testcase_02 AC 21 ms
9,144 KB
testcase_03 AC 98 ms
19,036 KB
testcase_04 AC 223 ms
34,780 KB
testcase_05 AC 27 ms
9,968 KB
testcase_06 AC 31 ms
10,488 KB
testcase_07 AC 116 ms
21,412 KB
testcase_08 AC 150 ms
25,904 KB
testcase_09 AC 100 ms
19,068 KB
testcase_10 AC 42 ms
11,328 KB
testcase_11 AC 82 ms
16,848 KB
testcase_12 AC 81 ms
16,744 KB
testcase_13 AC 40 ms
11,648 KB
testcase_14 AC 38 ms
11,184 KB
testcase_15 AC 35 ms
11,144 KB
testcase_16 AC 146 ms
25,260 KB
testcase_17 AC 82 ms
16,996 KB
testcase_18 AC 160 ms
26,812 KB
testcase_19 AC 56 ms
13,296 KB
testcase_20 AC 263 ms
39,700 KB
testcase_21 AC 172 ms
28,308 KB
testcase_22 AC 101 ms
18,792 KB
testcase_23 AC 135 ms
22,964 KB
testcase_24 AC 179 ms
28,612 KB
testcase_25 AC 43 ms
11,924 KB
testcase_26 AC 190 ms
30,552 KB
testcase_27 AC 158 ms
26,764 KB
testcase_28 AC 340 ms
49,364 KB
testcase_29 AC 335 ms
49,508 KB
testcase_30 AC 336 ms
49,488 KB
testcase_31 AC 338 ms
49,500 KB
testcase_32 AC 342 ms
49,440 KB
testcase_33 AC 337 ms
49,396 KB
testcase_34 AC 339 ms
49,468 KB
testcase_35 AC 337 ms
49,424 KB
testcase_36 AC 338 ms
49,324 KB
testcase_37 AC 339 ms
49,436 KB
testcase_38 AC 339 ms
49,380 KB
testcase_39 AC 339 ms
49,424 KB
testcase_40 AC 338 ms
49,444 KB
testcase_41 AC 339 ms
49,452 KB
testcase_42 AC 340 ms
49,628 KB
testcase_43 AC 339 ms
49,460 KB
testcase_44 AC 338 ms
49,516 KB
testcase_45 AC 339 ms
49,412 KB
testcase_46 AC 338 ms
49,500 KB
testcase_47 AC 339 ms
49,624 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