結果

問題 No.324 落ちてた閉路グラフ
ユーザー mkawa2mkawa2
提出日時 2020-02-27 11:04:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 1,095 bytes
コンパイル時間 2,431 ms
コンパイル使用メモリ 165,728 KB
実行使用メモリ 74,112 KB
最終ジャッジ日時 2024-04-21 16:50:24
合計ジャッジ時間 3,286 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 50 ms
73,988 KB
testcase_05 AC 59 ms
74,112 KB
testcase_06 AC 45 ms
73,984 KB
testcase_07 AC 61 ms
73,984 KB
testcase_08 AC 46 ms
74,112 KB
testcase_09 AC 38 ms
73,916 KB
testcase_10 AC 47 ms
73,984 KB
testcase_11 AC 39 ms
74,112 KB
testcase_12 AC 29 ms
68,992 KB
testcase_13 AC 15 ms
32,512 KB
testcase_14 AC 9 ms
12,160 KB
testcase_15 AC 14 ms
18,048 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 58 ms
74,112 KB
testcase_33 AC 57 ms
73,928 KB
testcase_34 AC 39 ms
61,056 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 23 ms
43,776 KB
testcase_37 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
const int inf = 1e9;
const ll md = 1000000007;

int dp[3005][3005][2];
int w[3005];

int main() {
  int n,m;
  cin>>n>>m;
  rep(i,n) cin>>w[i];

  rep(i,n+1) rep(j,n+1) rep(k,2) dp[i][j][k]=-inf;
  dp[0][0][1]=0;
  rep(i,n) rep(j,min(i+1,m+1)) rep(k,2){
    int pre=dp[i][j][k];
    if (pre==-inf) continue;
    dp[i+1][j][0]=max(dp[i+1][j][0],pre);
    if (k) dp[i+1][j+1][1]=max(dp[i+1][j+1][1],pre+w[i]);
    else dp[i+1][j+1][1]=max(dp[i+1][j+1][1],pre);
  }
  int ans=dp[n][m][1];

  rep(i,n+1) rep(j,n+1) rep(k,2) dp[i][j][k]=-inf;
  dp[0][0][0]=0;
  rep(i,n) rep(j,min(i+1,m+1)) rep(k,2){
    int pre=dp[i][j][k];
    if (pre==-inf) continue;
    dp[i+1][j][0]=max(dp[i+1][j][0],pre);
    if (k) dp[i+1][j+1][1]=max(dp[i+1][j+1][1],pre+w[i]);
    else dp[i+1][j+1][1]=max(dp[i+1][j+1][1],pre);
  }
  ans=max(ans,dp[n][m][0]);
  cout<<ans<<endl;
  return 0;
}
0