結果

問題 No.1782 ManyCoins
ユーザー mtsd
提出日時 2021-12-11 16:24:30
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 4,795 ms
コンパイル使用メモリ 163,456 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-07-19 21:58:10
合計ジャッジ時間 5,479 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long n,L,res,dp[1000010],w[20];
int main(){
  cin>>n>>L;
  rep(i,n)cin>>w[i];
  sort(w,w+n);
  fill(dp,dp+w[0],(1LL<<60));
  dp[0]=0;
  rep(i,n-1){
    int x=w[i+1]%w[0];
    int g=__gcd(w[0],w[i+1]);
    for(int s=0;s<g;s++){
      int t=s;
      rep(zz,2*w[0]/g){
        int p=(t+x);
        if(p>=w[0])p-=w[0];
        dp[p]=min(dp[p],dp[t]+w[i+1]);
        t=p;
      }
    }
  }
  dp[0]=w[0];
  rep(i,w[0]){
    if(L>=dp[i])res+=(L-dp[i])/w[0]+1;
  }
  cout<<res<<endl;
  return 0;
}
0