結果
問題 | No.1247 ブロック登り |
ユーザー | mkawa2 |
提出日時 | 2021-08-18 18:05:57 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,240 bytes |
コンパイル時間 | 172 ms |
コンパイル使用メモリ | 82,504 KB |
実行使用メモリ | 340,100 KB |
最終ジャッジ日時 | 2024-04-19 23:37:51 |
合計ジャッジ時間 | 5,959 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
58,112 KB |
testcase_01 | AC | 40 ms
52,224 KB |
testcase_02 | AC | 41 ms
53,248 KB |
testcase_03 | AC | 39 ms
52,608 KB |
testcase_04 | AC | 57 ms
66,048 KB |
testcase_05 | AC | 57 ms
65,280 KB |
testcase_06 | AC | 39 ms
52,480 KB |
testcase_07 | AC | 194 ms
79,884 KB |
testcase_08 | AC | 172 ms
80,348 KB |
testcase_09 | AC | 153 ms
79,280 KB |
testcase_10 | AC | 155 ms
78,772 KB |
testcase_11 | TLE | - |
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 from array import array n, k = LI() aa = LI() dp = [[[array('i',[-inf]*n) for _ in range(n)] for _ in range(2)] for _ in range(k+1)] for i, a in enumerate(aa): dp[k][0][i][i] = a*k def chmax(i, l, r, j, val): if val > dp[i][j][l][r]: dp[i][j][l][r] = val for i in range(k, 0, -1): for l in range(n): for r in range(l, n): for j in range(2): pre = dp[i][j][l][r] if pre == -inf: continue # 左に出る d = r-l+1 if j else 1 if l-1 >= 0 and i-d >= 0: chmax(i-d, l-1, r, 0, 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, l, r+1, 1, pre+(i-d)*aa[r+1]) # 動かない if l != r: chmax(i-2, l, r, j, pre) ans = [-inf]*n for j in range(n): for r in range(j,n): for i in range(k): if j-i<0:break ans[j]=max(ans[j],dp[i][0][j-i][r]) for l in range(j+1): for i in range(k): if j+i==n:break ans[j]=max(ans[j],dp[i][1][l][j+i]) print(*ans,sep="\n")