結果
| 問題 |
No.324 落ちてた閉路グラフ
|
| ユーザー |
btk
|
| 提出日時 | 2015-12-17 11:40:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,149 bytes |
| コンパイル時間 | 1,597 ms |
| コンパイル使用メモリ | 167,048 KB |
| 実行使用メモリ | 817,408 KB |
| 最終ジャッジ日時 | 2024-09-16 07:21:31 |
| 合計ジャッジ時間 | 5,362 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 1 MLE * 1 -- * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
#define USED 1
#define UNUSED 0
const LL INF=((LL)1e7)*((LL)1e7);
int main() {
int n,m;cin>>n>>m;
V w(n);for(auto& it : w)cin>>it;
VVV dp_nonloop(n,VV(m+1,V(2,-INF)));
VVV dp_loop(n,VV(m+1,V(2,-INF)));
dp_nonloop[0][0][UNUSED]=0;
dp_loop[0][1][USED]=0;
for(int i = 1; i < n; i++){
for(int j=0;j<=m;j++){
if(j<m)dp_nonloop[i][j+1][USED]=max(dp_nonloop[i-1][j][USED]+w[i-1],dp_nonloop[i-1][j][UNUSED]);
dp_nonloop[i][j][UNUSED]=max(dp_nonloop[i-1][j][USED],dp_nonloop[i-1][j][UNUSED]);
if(j<m)dp_loop[i][j+1][USED]=max(dp_loop[i-1][j][USED]+w[i-1],dp_loop[i-1][j][UNUSED]);
dp_loop[i][j][UNUSED]=max(dp_loop[i-1][j][USED],dp_loop[i-1][j][UNUSED]);
}
}
for(int j = 2; j <= m; j++)dp_loop[n-1][j][USED]+=w[n-1];
LL res=-INF;
for(auto& i : dp_nonloop)for(auto& j : i)for(auto& k : j)res=max(res,k);
for(auto& i : dp_loop)for(auto& j : i)for(auto& k : j)res=max(res,k);
cout<<res<<endl;
return 0;
}
btk