結果

問題 No.324 落ちてた閉路グラフ
ユーザー btkbtk
提出日時 2015-12-17 11:44:44
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,123 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 153,080 KB
実行使用メモリ 814,544 KB
最終ジャッジ日時 2023-10-14 12:31:32
合計ジャッジ時間 5,663 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 661 ms
382,404 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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& k : i[m])res=max(res,k);
    for(auto& i : dp_loop)for(auto& k : i[m])res=max(res,k);
    cout<<res<<endl;
    return 0;
}
0