結果
問題 |
No.1782 ManyCoins
|
ユーザー |
![]() |
提出日時 | 2021-12-11 16:03:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 147 ms / 2,000 ms |
コード長 | 757 bytes |
コンパイル時間 | 1,508 ms |
コンパイル使用メモリ | 172,232 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-07-19 21:14:08 |
合計ジャッジ時間 | 3,426 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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++) typedef long long ll; ll n,L,res; ll dp[1000010]; int main(){ cin >> n >> L; vector<ll>w(n); rep(i,n)cin >> w[i]; sort(w.begin(),w.end()); 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; } } } rep(i,w[0]){ res += max(0ll,(L-i)/w[0] - (dp[i]-i + w[0]-1)/w[0] + 1); } cout << res-1 << endl; return 0; }