結果

問題 No.324 落ちてた閉路グラフ
ユーザー btkbtk
提出日時 2015-12-17 12:43:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 1,178 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 146,996 KB
実行使用メモリ 74,028 KB
最終ジャッジ日時 2023-08-09 21:39:27
合計ジャッジ時間 4,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
73,748 KB
testcase_01 AC 37 ms
73,700 KB
testcase_02 AC 38 ms
73,704 KB
testcase_03 AC 38 ms
73,688 KB
testcase_04 AC 52 ms
73,704 KB
testcase_05 AC 73 ms
73,760 KB
testcase_06 AC 52 ms
73,800 KB
testcase_07 AC 70 ms
73,840 KB
testcase_08 AC 51 ms
73,708 KB
testcase_09 AC 44 ms
73,700 KB
testcase_10 AC 51 ms
73,776 KB
testcase_11 AC 44 ms
73,832 KB
testcase_12 AC 38 ms
73,800 KB
testcase_13 AC 38 ms
73,712 KB
testcase_14 AC 41 ms
73,696 KB
testcase_15 AC 43 ms
73,704 KB
testcase_16 AC 38 ms
73,716 KB
testcase_17 AC 38 ms
74,028 KB
testcase_18 AC 38 ms
73,768 KB
testcase_19 AC 38 ms
73,688 KB
testcase_20 AC 38 ms
73,688 KB
testcase_21 AC 37 ms
73,704 KB
testcase_22 AC 38 ms
73,708 KB
testcase_23 AC 38 ms
73,752 KB
testcase_24 AC 37 ms
73,824 KB
testcase_25 AC 37 ms
73,704 KB
testcase_26 AC 38 ms
73,896 KB
testcase_27 AC 38 ms
73,760 KB
testcase_28 AC 37 ms
73,808 KB
testcase_29 AC 38 ms
73,764 KB
testcase_30 AC 38 ms
73,752 KB
testcase_31 AC 37 ms
73,768 KB
testcase_32 AC 71 ms
73,780 KB
testcase_33 AC 65 ms
73,780 KB
testcase_34 AC 51 ms
73,908 KB
testcase_35 AC 38 ms
73,700 KB
testcase_36 AC 44 ms
73,716 KB
testcase_37 AC 39 ms
73,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef int LL;
typedef vector<LL> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
#define USED 1
#define UNUSED 0
const LL INF=((LL)1e8);
int dp[3000][3001][2];
inline void init(){
    for(int i=0;i<3000;i++)
    for(int j=0;j<=3000;j++)
    for(int k=0;k<2;k++)dp[i][j][k]=-INF;
}
int main() {
    int n,m;cin>>n>>m;
    V w(n);for(auto& it : w)cin>>it;
    LL res=-INF;
    init();dp[0][0][UNUSED]=0;
    for(int i = 1; i < n; i++){
        for(int j=0;j<=m;j++){
            if(j<m)dp[i][j+1][USED]=max(dp[i-1][j][USED]+w[i-1],dp[i-1][j][UNUSED]);
            dp[i][j][UNUSED]=max(dp[i-1][j][USED],dp[i-1][j][UNUSED]);
        }
    }
    for(int i=max(0,m-1);i<n;i++)for(int j=0;j<2;j++)res=max(res,dp[i][m][j]);


    init();dp[0][1][USED]=0;
    for(int i = 1; i < n; i++){
        for(int j=0;j<=m;j++){
            if(j<m)dp[i][j+1][USED]=max(dp[i-1][j][USED]+w[i-1],dp[i-1][j][UNUSED]);
            dp[i][j][UNUSED]=max(dp[i-1][j][USED],dp[i-1][j][UNUSED]);
        }
    }
    dp[n-1][m][USED]+=w[n-1];

    for(int i=max(0,m-1);i<n;i++)for(int j=0;j<2;j++)res=max(res,dp[i][m][j]);
    cout<<res<<endl;
    return 0;
}
0