結果

問題 No.324 落ちてた閉路グラフ
ユーザー nanophoto12nanophoto12
提出日時 2015-12-27 22:29:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 1,490 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 71,060 KB
実行使用メモリ 326,300 KB
最終ジャッジ日時 2024-04-27 16:06:33
合計ジャッジ時間 10,591 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 233 ms
326,228 KB
testcase_01 AC 234 ms
326,196 KB
testcase_02 AC 224 ms
326,252 KB
testcase_03 AC 223 ms
326,196 KB
testcase_04 AC 240 ms
326,044 KB
testcase_05 AC 256 ms
326,212 KB
testcase_06 AC 237 ms
326,120 KB
testcase_07 AC 251 ms
326,300 KB
testcase_08 AC 239 ms
326,244 KB
testcase_09 AC 235 ms
325,980 KB
testcase_10 AC 245 ms
326,248 KB
testcase_11 AC 241 ms
325,984 KB
testcase_12 AC 231 ms
326,180 KB
testcase_13 AC 232 ms
326,188 KB
testcase_14 AC 230 ms
326,204 KB
testcase_15 AC 228 ms
326,240 KB
testcase_16 AC 233 ms
326,192 KB
testcase_17 AC 228 ms
326,028 KB
testcase_18 AC 227 ms
326,232 KB
testcase_19 AC 224 ms
326,112 KB
testcase_20 AC 229 ms
326,260 KB
testcase_21 AC 229 ms
326,152 KB
testcase_22 AC 231 ms
326,152 KB
testcase_23 AC 226 ms
326,224 KB
testcase_24 AC 227 ms
326,132 KB
testcase_25 AC 227 ms
325,980 KB
testcase_26 AC 225 ms
326,168 KB
testcase_27 AC 230 ms
326,160 KB
testcase_28 AC 224 ms
326,196 KB
testcase_29 AC 228 ms
326,268 KB
testcase_30 AC 250 ms
326,256 KB
testcase_31 AC 224 ms
326,176 KB
testcase_32 AC 253 ms
326,096 KB
testcase_33 AC 255 ms
326,220 KB
testcase_34 AC 241 ms
326,124 KB
testcase_35 AC 223 ms
326,120 KB
testcase_36 AC 230 ms
326,080 KB
testcase_37 AC 232 ms
326,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#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 N,M;
int W[5000];
int dp[3][3][3030][3030];

void solve() {
    
    cin>>N>>M;
    FOR(i,N) cin>>W[i];
    
    memset(dp,0xce,sizeof(dp));
    
    dp[0][0][0][0]=dp[1][1][0][1]=0;
    int ma=-100000000;
    FOR(r,2) {
        FOR(i,N-1) {
            FOR(j,M+1) {
                dp[r][0][i+1][j]=max(dp[r][0][i][j],dp[r][1][i][j]);
                if(j) dp[r][1][i+1][j]=max(dp[r][0][i][j-1],dp[r][1][i][j-1]+W[i]);
            }
        }
        
        ma=max(ma,dp[r][0][N-1][M]);
        if(r==0) ma=max(ma,dp[r][1][N-1][M]);
        if(r==1) ma=max(ma,dp[r][1][N-1][M]+W[N-1]);
    }
    
    
    cout<<ma<<endl;
    
}
int main() {
    solve();
    return 0;
}
0