結果

問題 No.783 門松計画
ユーザー beetbeet
提出日時 2019-01-11 21:34:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,703 bytes
コンパイル時間 2,279 ms
コンパイル使用メモリ 209,652 KB
実行使用メモリ 81,464 KB
最終ジャッジ日時 2023-09-30 18:38:16
合計ジャッジ時間 6,272 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
81,320 KB
testcase_01 AC 89 ms
81,260 KB
testcase_02 AC 89 ms
81,284 KB
testcase_03 AC 89 ms
81,208 KB
testcase_04 AC 87 ms
81,192 KB
testcase_05 AC 86 ms
81,452 KB
testcase_06 AC 88 ms
81,252 KB
testcase_07 AC 88 ms
81,284 KB
testcase_08 AC 90 ms
81,296 KB
testcase_09 AC 87 ms
81,160 KB
testcase_10 AC 157 ms
81,200 KB
testcase_11 AC 150 ms
81,188 KB
testcase_12 AC 155 ms
81,160 KB
testcase_13 AC 91 ms
81,464 KB
testcase_14 AC 111 ms
81,316 KB
testcase_15 AC 104 ms
81,184 KB
testcase_16 AC 91 ms
81,156 KB
testcase_17 AC 92 ms
81,184 KB
testcase_18 AC 91 ms
81,136 KB
testcase_19 AC 112 ms
81,184 KB
testcase_20 AC 88 ms
81,308 KB
testcase_21 AC 89 ms
81,132 KB
testcase_22 AC 91 ms
81,184 KB
testcase_23 AC 86 ms
81,156 KB
testcase_24 AC 110 ms
81,256 KB
testcase_25 AC 95 ms
81,240 KB
testcase_26 AC 94 ms
81,160 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;}


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

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

  const Int INF = 1e15;
  auto dp=make_v<Int>(55,55,55,55);
  fill_v(dp,-INF);
  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      if(l[i]!=l[j]) dp[0][min(w[i]+w[j],c+1)][i][j]=l[i]+l[j];

  auto is_kado=[](Int a,Int b,Int c){
                 if(a==b||b==c||a==c) return 0;
                 if(a<b&&b>c) return 1;
                 if(a>b&&b<c) return 1;
                 return 0;
               };
  
  for(Int x=0;x<2;x++){
    for(Int y=0;y<=c;y++){
      for(Int i=0;i<n;i++){
        for(Int j=0;j<n;j++){
          for(Int k=0;k<n;k++){
            if(!is_kado(l[i],l[j],l[k])) continue;
            chmax(dp[1][min(y+w[k],c+1)][j][k],dp[x][y][i][j]+l[k]);
          }
        }
      }
    }
  }

  Int ans=0;
  for(Int y=0;y<=c;y++)
    for(Int i=0;i<n;i++)
      for(Int j=0;j<n;j++)
        chmax(ans,dp[1][y][i][j]);
  
  cout<<ans<<endl;
  return 0;
}
0