結果
| 問題 |
No.1782 ManyCoins
|
| コンテスト | |
| ユーザー |
kiyoshi0205
|
| 提出日時 | 2021-12-11 09:55:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,551 ms / 2,000 ms |
| コード長 | 655 bytes |
| コンパイル時間 | 2,104 ms |
| コンパイル使用メモリ | 200,960 KB |
| 最終ジャッジ日時 | 2025-01-26 07:46:43 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0;i<N;++i)
int N,w[20],d;
ll L,dp[1000000],ans;
bool vis[1000000];
int main(){
cin.tie(0)->sync_with_stdio(0);
cin>>N>>L;
rep(i,N){
cin>>w[i];
d=gcd(d,w[i]);
}
L/=d;
rep(i,N)w[i]/=d;
sort(w,w+N);
priority_queue<ll,vector<ll>,greater<ll>> que;
que.emplace(0);
while(!que.empty()){
ll x=que.top();que.pop();
int a=x%w[0];
if(vis[a])continue;
vis[a]=true;
dp[a]=x;
rep(i,N)if(!vis[(a+w[i])%w[0]])que.emplace(x+w[i]);
}
rep(i,w[0]){
if(L<dp[i])continue;
ans+=(L-dp[i])/w[0]+1;
}
cout<<ans-1<<'\n';
}
kiyoshi0205