結果

問題 No.324 落ちてた閉路グラフ
ユーザー mkawa2mkawa2
提出日時 2020-02-27 11:02:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,094 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 164,436 KB
実行使用メモリ 74,120 KB
最終ジャッジ日時 2024-04-21 16:50:20
合計ジャッジ時間 3,154 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 38 ms
69,120 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
5,376 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 <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,1){
    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,1){
    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