結果
問題 | No.1247 ブロック登り |
ユーザー | mkawa2 |
提出日時 | 2021-08-18 18:51:12 |
言語 | PyPy3 (7.3.13) |
結果 |
MLE
|
実行時間 | - |
コード長 | 845 bytes |
コンパイル時間 | 568 ms |
コンパイル使用メモリ | 87,252 KB |
実行使用メモリ | 598,096 KB |
最終ジャッジ日時 | 2023-08-01 23:28:04 |
合計ジャッジ時間 | 8,254 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 65 ms
71,324 KB |
testcase_01 | AC | 66 ms
71,408 KB |
testcase_02 | AC | 72 ms
75,304 KB |
testcase_03 | AC | 67 ms
71,240 KB |
testcase_04 | AC | 77 ms
76,352 KB |
testcase_05 | AC | 72 ms
75,904 KB |
testcase_06 | AC | 64 ms
71,332 KB |
testcase_07 | AC | 435 ms
98,336 KB |
testcase_08 | AC | 459 ms
104,220 KB |
testcase_09 | AC | 284 ms
86,200 KB |
testcase_10 | AC | 312 ms
86,872 KB |
testcase_11 | MLE | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
ソースコード
import sys def LI(): return list(map(int, sys.stdin.readline().split())) inf = 10**9 n, k = LI() aa = LI() dp = [{} for _ in range(k+1)] for i, a in enumerate(aa): dp[k][0, i, i] = a*k def chmax(i, j, l, r, val): now = dp[i].setdefault((j, l, r), -inf) if val > now: dp[i][j, l, r] = val ans = [-inf]*n for i in range(k, -1, -1): for (j, l, r), pre in dp[i].items(): p0 = r-i if j else l+i if l <= p0 <= r: ans[p0] = max(ans[p0], pre) if i == 0: continue # 左に出る d = r-l+1 if j else 1 if l-1 >= 0 and i-d >= 0: chmax(i-d, 0, l-1, r, pre+(i-d)*aa[l-1]) # 右に出る d = 1 if j else r-l+1 if r+1 < n and i-d >= 0: chmax(i-d, 1, l, r+1, pre+(i-d)*aa[r+1]) # 動かない if l != r: chmax(i-2, j, l, r, pre) print(*ans, sep="\n")