結果

問題 No.324 落ちてた閉路グラフ
ユーザー beetbeet
提出日時 2018-12-03 19:41:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 977 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 202,084 KB
実行使用メモリ 290,544 KB
最終ジャッジ日時 2023-09-17 15:45:53
合計ジャッジ時間 7,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
290,236 KB
testcase_01 AC 80 ms
290,288 KB
testcase_02 AC 78 ms
290,292 KB
testcase_03 AC 78 ms
290,336 KB
testcase_04 AC 139 ms
290,408 KB
testcase_05 AC 139 ms
290,256 KB
testcase_06 AC 136 ms
290,260 KB
testcase_07 AC 138 ms
290,260 KB
testcase_08 AC 136 ms
290,372 KB
testcase_09 AC 137 ms
290,260 KB
testcase_10 AC 139 ms
290,320 KB
testcase_11 AC 136 ms
290,460 KB
testcase_12 AC 129 ms
290,352 KB
testcase_13 AC 97 ms
290,344 KB
testcase_14 AC 85 ms
290,516 KB
testcase_15 AC 88 ms
290,340 KB
testcase_16 AC 78 ms
290,236 KB
testcase_17 AC 78 ms
290,308 KB
testcase_18 AC 79 ms
290,544 KB
testcase_19 AC 80 ms
290,264 KB
testcase_20 AC 80 ms
290,212 KB
testcase_21 AC 80 ms
290,276 KB
testcase_22 AC 80 ms
290,228 KB
testcase_23 AC 80 ms
290,276 KB
testcase_24 AC 78 ms
290,328 KB
testcase_25 AC 80 ms
290,288 KB
testcase_26 AC 79 ms
290,212 KB
testcase_27 AC 79 ms
290,232 KB
testcase_28 AC 80 ms
290,288 KB
testcase_29 AC 79 ms
290,232 KB
testcase_30 AC 79 ms
290,296 KB
testcase_31 AC 79 ms
290,272 KB
testcase_32 AC 138 ms
290,260 KB
testcase_33 AC 137 ms
290,260 KB
testcase_34 AC 120 ms
290,308 KB
testcase_35 AC 79 ms
290,396 KB
testcase_36 AC 108 ms
290,300 KB
testcase_37 AC 80 ms
290,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int dp[2][2][3030][3030];
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> w(n);
  for(Int i=0;i<n;i++) cin>>w[i];

  const Int INF = 1e12;
  for(Int a=0;a<2;a++)
    for(Int b=0;b<2;b++)
      for(Int i=0;i<3030;i++)
        for(Int j=0;j<3030;j++)
          dp[a][b][i][j]=-INF;

  dp[0][0][1][0]=0;
  dp[1][1][1][1]=0;
  
  for(Int i=1;i<n;i++){
    for(Int j=0;j<=n;j++){
      for(Int a=0;a<2;a++){
        for(Int b=0;b<2;b++){
          chmax(dp[a][0][i+1][j],dp[a][b][i][j]);
          chmax(dp[a][1][i+1][j+1],dp[a][b][i][j]+b*w[i]);
        }
      }
    }
  }

  Int ans=dp[0][0][n][m];
  for(Int a=0;a<2;a++)
    for(Int b=0;b<2;b++)
      chmax(ans,dp[a][b][n][m]+(a&&b)*w[0]);  
  cout<<ans<<endl;  
  return 0;
}
0