結果

問題 No.324 落ちてた閉路グラフ
ユーザー btkbtk
提出日時 2015-12-17 12:43:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,178 bytes
コンパイル時間 1,152 ms
コンパイル使用メモリ 160,624 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2024-04-27 16:02:45
合計ジャッジ時間 4,218 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
73,708 KB
testcase_01 AC 44 ms
73,728 KB
testcase_02 AC 45 ms
73,640 KB
testcase_03 AC 43 ms
73,600 KB
testcase_04 AC 59 ms
73,704 KB
testcase_05 AC 81 ms
73,780 KB
testcase_06 AC 57 ms
73,836 KB
testcase_07 AC 78 ms
73,700 KB
testcase_08 AC 57 ms
73,728 KB
testcase_09 AC 51 ms
73,728 KB
testcase_10 AC 57 ms
73,728 KB
testcase_11 AC 64 ms
73,728 KB
testcase_12 AC 37 ms
73,856 KB
testcase_13 AC 36 ms
73,856 KB
testcase_14 AC 40 ms
73,812 KB
testcase_15 AC 42 ms
73,696 KB
testcase_16 AC 37 ms
73,800 KB
testcase_17 AC 37 ms
73,812 KB
testcase_18 AC 36 ms
73,776 KB
testcase_19 AC 37 ms
73,792 KB
testcase_20 AC 35 ms
73,728 KB
testcase_21 AC 35 ms
73,844 KB
testcase_22 AC 37 ms
73,728 KB
testcase_23 AC 37 ms
73,820 KB
testcase_24 AC 36 ms
73,788 KB
testcase_25 AC 37 ms
73,672 KB
testcase_26 AC 37 ms
73,812 KB
testcase_27 AC 37 ms
73,792 KB
testcase_28 AC 35 ms
73,856 KB
testcase_29 AC 36 ms
73,840 KB
testcase_30 AC 36 ms
73,652 KB
testcase_31 AC 36 ms
73,728 KB
testcase_32 AC 72 ms
73,728 KB
testcase_33 AC 67 ms
73,856 KB
testcase_34 AC 50 ms
73,856 KB
testcase_35 AC 36 ms
73,600 KB
testcase_36 AC 40 ms
73,728 KB
testcase_37 AC 36 ms
73,764 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