結果
問題 | No.1536 仕切り直し |
ユーザー | H3PO4 |
提出日時 | 2022-10-08 09:09:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 258 ms / 2,000 ms |
コード長 | 811 bytes |
コンパイル時間 | 1,711 ms |
コンパイル使用メモリ | 86,528 KB |
実行使用メモリ | 122,912 KB |
最終ジャッジ日時 | 2023-09-04 08:05:47 |
合計ジャッジ時間 | 3,352 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,020 KB |
testcase_01 | AC | 75 ms
71,020 KB |
testcase_02 | AC | 75 ms
71,024 KB |
testcase_03 | AC | 102 ms
76,456 KB |
testcase_04 | AC | 150 ms
91,084 KB |
testcase_05 | AC | 212 ms
107,908 KB |
testcase_06 | AC | 105 ms
77,288 KB |
testcase_07 | AC | 102 ms
76,352 KB |
testcase_08 | AC | 150 ms
88,932 KB |
testcase_09 | AC | 159 ms
90,612 KB |
testcase_10 | AC | 258 ms
122,912 KB |
testcase_11 | AC | 128 ms
84,756 KB |
testcase_12 | AC | 205 ms
108,968 KB |
ソースコード
N, M = map(int, input().split()) A = map(int, input().split()) def sign(x): return -1 if (x & 1) else 1 dp = [[-10 ** 18] * (M + 1) for _ in range(N + 1)] partition_flag = [[False] * (M + 1) for _ in range(N + 1)] for j in range(M + 1): dp[0][j] = 0 for i, a in enumerate(A): for j in range(min(i + 1, M + 1)): dp[i + 1][j] = dp[i][j] + sign(j) * a for j in range(1, M + 1): if dp[i + 1][j] < dp[i][j - 1] + sign(j) * a: partition_flag[i + 1][j] = True dp[i + 1][j] = dp[i][j - 1] + sign(j) * a # 復元 max_index = dp[N].index(max(dp[N])) ans = [] j = max_index for i in range(N, 0, -1): if partition_flag[i][j]: ans.append(i - 1) j -= 1 assert j >= 0 ans.reverse() ans.extend([N] * (M - len(ans))) print(*ans, sep="\n")