結果
| 問題 | No.783 門松計画 | 
| コンテスト | |
| ユーザー |  beet | 
| 提出日時 | 2019-01-11 21:34:39 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 148 ms / 2,000 ms | 
| コード長 | 1,703 bytes | 
| コンパイル時間 | 2,099 ms | 
| コンパイル使用メモリ | 206,960 KB | 
| 最終ジャッジ日時 | 2025-01-06 20:16:36 | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#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;
}
            
            
            
        