結果
問題 |
No.1782 ManyCoins
|
ユーザー |
![]() |
提出日時 | 2021-12-11 16:12:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 129 ms / 2,000 ms |
コード長 | 703 bytes |
コンパイル時間 | 1,658 ms |
コンパイル使用メモリ | 169,484 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-07-19 21:34:57 |
合計ジャッジ時間 | 3,312 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 48 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)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; }