結果

問題 No.324 落ちてた閉路グラフ
ユーザー nanophoto12nanophoto12
提出日時 2015-12-27 22:31:24
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,916 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 70,040 KB
実行使用メモリ 394,300 KB
最終ジャッジ日時 2023-10-19 11:24:36
合計ジャッジ時間 8,529 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
394,288 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 179 ms
394,300 KB
testcase_05 WA -
testcase_06 AC 176 ms
394,300 KB
testcase_07 AC 194 ms
394,300 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 171 ms
394,292 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 164 ms
394,288 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 165 ms
394,288 KB
testcase_24 WA -
testcase_25 AC 172 ms
394,288 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 164 ms
394,288 KB
testcase_29 AC 166 ms
394,288 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define FOR(x,y) for(int x = 0;x < y;x++)
#define LLI long long int

template<int um> class UF {
public:
    vector<int> par,rank,cnt;
    UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
    void reinit() {FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
    int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
    int count(int x) { return cnt[operator[](x)];}
    int operator()(int x,int y) {
        if((x=operator[](x))==(y=operator[](y))) return x;
        cnt[y]=cnt[x]=cnt[x]+cnt[y];
        if(rank[x]>rank[y]) return par[x]=y;
        rank[x]+=rank[x]==rank[y]; return par[y]=x;
    }
};

int dp[2][2][5000][5000];
int w[5000];

int main() {
    int n, m;
    cin >> n >> m;
    FOR(i, n)
    {
        cin >> w[i];
    }
    int* pointer = &dp[0][0][0][0];
    FOR(i, 2 * 2 * 5000 * 5000)
    {
        pointer[i] = INT32_MIN;
    }
    dp[0][0][0][0] = 0;
    dp[1][1][0][1] = 0;
    int maxValue = INT32_MIN;
    FOR(u ,2)
    {
        FOR(i, n-1)
        {
            FOR(j,m + 1)
            {
                dp[u][0][i+1][j] = max(dp[u][0][i][j], dp[u][1][i][j]);
                //cout << "not used" << dp[u][0][i+1][j] << endl;
                if(j > 0)
                {
                    dp[u][1][i+1][j] = max(dp[u][0][i][j-1], dp[u][1][i][j-1] + w[i]);
                    //cout << "used" << dp[u][1][i+1][j] << endl;
                }
            }
        }
        maxValue = max(maxValue, dp[u][0][n-1][m]);
        if(u == 0)
        {
            maxValue = max(maxValue, dp[u][1][n-1][m]);
        }
        else if(u == 1)
        {
            maxValue = max(maxValue, dp[u][1][n-1][m] + w[n-1]);
        }
        //cout << "max " << maxValue << endl;
    }
    cout << maxValue << endl;
    return 0;
}
0