結果
問題 | No.1536 仕切り直し |
ユーザー | H3PO4 |
提出日時 | 2022-10-08 09:06:03 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 799 bytes |
コンパイル時間 | 280 ms |
コンパイル使用メモリ | 86,908 KB |
実行使用メモリ | 122,976 KB |
最終ジャッジ日時 | 2023-09-04 07:55:49 |
合計ジャッジ時間 | 4,140 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,348 KB |
testcase_01 | AC | 73 ms
71,364 KB |
testcase_02 | AC | 71 ms
70,936 KB |
testcase_03 | AC | 105 ms
76,424 KB |
testcase_04 | AC | 153 ms
91,360 KB |
testcase_05 | WA | - |
testcase_06 | AC | 99 ms
77,360 KB |
testcase_07 | AC | 95 ms
76,556 KB |
testcase_08 | AC | 144 ms
89,348 KB |
testcase_09 | AC | 152 ms
90,704 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
ソースコード
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(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")