結果
問題 | No.1536 仕切り直し |
ユーザー | logx |
提出日時 | 2021-03-24 23:12:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 727 bytes |
コンパイル時間 | 553 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 195,220 KB |
最終ジャッジ日時 | 2024-05-04 00:45:55 |
合計ジャッジ時間 | 4,297 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,096 KB |
testcase_01 | AC | 43 ms
51,968 KB |
testcase_02 | AC | 43 ms
51,968 KB |
testcase_03 | AC | 113 ms
77,824 KB |
testcase_04 | AC | 240 ms
113,536 KB |
testcase_05 | WA | - |
testcase_06 | AC | 87 ms
75,136 KB |
testcase_07 | AC | 112 ms
77,172 KB |
testcase_08 | AC | 194 ms
100,224 KB |
testcase_09 | AC | 217 ms
101,888 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
ソースコード
n,m=map(int,input().split()) a=list(map(int,input().split())) dp=[[-10**19]*(m+1) for i in range(n)] dp[0][0]=0 dp[0][0]=a[0] dp[0][1]=-a[0] def val(x,cnt): if cnt&1: return -x return x for i in range(n-1): for j in range(m+1): dp[i+1][j]=max(dp[i+1][j],dp[i][j]+val(a[i+1],j)) if j<m: dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+val(a[i+1],j+1)) res=-10**19 idx=-1 for j in range(m+1): if res<dp[n-1][j]: res=dp[n-1][j] idx=j ans=[] for i in reversed(range(n-1)): if dp[i+1][idx]!=dp[i][idx]+val(a[i+1],idx): idx-=1 ans.append(i+1) if idx>0: ans.append(1) for i in reversed(ans): print(i) for i in range(m-len(ans)): print(n)