結果

問題 No.27 板の準備
ユーザー beet
提出日時 2018-11-23 14:59:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 196,208 KB
最終ジャッジ日時 2025-01-06 17:12:32
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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
signed main(){
  vector<Int> v(4);
  for(Int i=0;i<4;i++) cin>>v[i];
  Int ans=accumulate(v.begin(),v.end(),0LL);
  for(Int a=1;a<=30;a++){
    for(Int b=a+1;b<=30;b++){
      for(Int c=b+a;c<=30;c++){
        vector<Int> dp(31,ans);
        dp[0]=0;
        for(Int i=0;i<=30;i++){
          if(i-a>=0) chmin(dp[i],dp[i-a]+1);          
          if(i-b>=0) chmin(dp[i],dp[i-b]+1);
          if(i-c>=0) chmin(dp[i],dp[i-c]+1);
        }
        Int res=0;
        for(Int i=0;i<4;i++) res+=dp[v[i]];
        chmin(ans,res);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}
0