結果

問題 No.1536 仕切り直し
ユーザー 👑 rin204rin204
提出日時 2022-04-15 16:28:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 123,336 KB
最終ジャッジ日時 2023-08-26 06:03:02
合計ジャッジ時間 3,102 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,252 KB
testcase_01 AC 75 ms
71,472 KB
testcase_02 AC 75 ms
71,428 KB
testcase_03 AC 96 ms
76,324 KB
testcase_04 AC 143 ms
90,728 KB
testcase_05 AC 197 ms
107,940 KB
testcase_06 AC 98 ms
77,420 KB
testcase_07 AC 96 ms
76,328 KB
testcase_08 AC 135 ms
89,128 KB
testcase_09 AC 145 ms
90,352 KB
testcase_10 AC 244 ms
123,336 KB
testcase_11 AC 125 ms
84,820 KB
testcase_12 AC 196 ms
108,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
A = list(map(int, input().split()))

min_ = [[0] * (m + 1) for _ in range(n + 1)]
max_ = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n - 1, -1, -1):
    for j in range(m + 1):
        min_[i][j] = min_[i + 1][j] + A[i]
        max_[i][j] = max_[i + 1][j] + A[i]
        if j != 0:
            min_[i][j] = min(min_[i][j], -max_[i + 1][j - 1] - A[i])
            max_[i][j] = max(max_[i][j], -min_[i + 1][j - 1] - A[i])

ans = []
t = 0
for i in range(n):
    if t == 0:
        if max_[i][m] == -min_[i + 1][m - 1] - A[i]:
            ans.append(i)
            m -= 1
            t ^= 1
    else:
        if min_[i][m] == -max_[i + 1][m - 1] - A[i]:
            ans.append(i)
            m -= 1
            t ^= 1
    if m == 0:
        break
ans += [n] * m
print(*ans, sep="\n")
0