結果

問題 No.324 落ちてた閉路グラフ
ユーザー h_nosonh_noson
提出日時 2016-06-19 17:48:06
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 868 bytes
コンパイル時間 1,150 ms
コンパイル使用メモリ 64,760 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2024-04-19 20:37:46
合計ジャッジ時間 7,129 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 TLE -
testcase_05 -- -
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 <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int w[3000];
int n;

int dfs(int pre, int now, int m, bool fst) {
    int ret1, ret2 = -INF;
    if (now < n) {
        ret1 = dfs(pre,now+1,m,fst);
        if (m > 0)
            ret2 = dfs(now,now+1,m-1,fst) + (pre + 1 == now ? w[pre] : 0);
    }
    else if (m > 0)
        ret1 = -INF;
    else
        ret1 = fst && pre + 1 == now ? w[n-1] : 0;
    return max(ret1,ret2);
}

int main(void) {
    int i, m;
    cin >> n >> m;
    rep (i,n) cin >> w[i];
    cout << max(dfs(0,1,m-1,true),dfs(-1,1,m,false)) << endl;
    return 0;
}
0