結果

問題 No.324 落ちてた閉路グラフ
ユーザー mamekinmamekin
提出日時 2015-12-19 21:17:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 549 ms / 5,000 ms
コード長 1,423 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 95,096 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-09 21:43:06
合計ジャッジ時間 5,521 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 217 ms
4,376 KB
testcase_05 AC 549 ms
4,380 KB
testcase_06 AC 176 ms
4,380 KB
testcase_07 AC 501 ms
4,376 KB
testcase_08 AC 189 ms
4,380 KB
testcase_09 AC 80 ms
4,376 KB
testcase_10 AC 189 ms
4,376 KB
testcase_11 AC 80 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 44 ms
4,380 KB
testcase_15 AC 81 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 532 ms
4,380 KB
testcase_33 AC 441 ms
4,376 KB
testcase_34 AC 191 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 45 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> w(n);
    for(int i=0; i<n; ++i)
        cin >> w[i];

    vector<vector<int> > dp(m+1, vector<int>(4, -INF));
    dp[m][0] = 0;
    for(int i=0; i<n; ++i){
        vector<vector<int> > nextDp(m+1, vector<int>(4, -INF));
        for(int a=0; a<=m; ++a){
            for(int b=0; b<4; ++b){
                nextDp[a][b&2] = max(nextDp[a][b&2], dp[a][b]);
                if(a > 0){
                    int x = 0;
                    if(b & 1)
                        x += w[i];
                    if(i == n - 1 && (b & 2))
                        x += w[0];

                    if(i == 0)
                        nextDp[a-1][b|3] = max(nextDp[a-1][b|3], dp[a][b] + x);
                    else
                        nextDp[a-1][b|1] = max(nextDp[a-1][b|1], dp[a][b] + x);
                }
            }
        }
        dp.swap(nextDp);
    }

    int ans = *max_element(dp[0].begin(), dp[0].end());
    cout << ans << endl;

    return 0;
}
0