結果

問題 No.1782 ManyCoins
ユーザー Ryuhei Mori
提出日時 2021-12-11 21:10:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 87,460 KB
最終ジャッジ日時 2025-01-26 07:58:38
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using u32 = unsigned int;
using u64 = unsigned long long int;

int main(){
  u32 n;
  u64 l;
  std::cin >> n >> l;

  std::vector<u32> w;

  for(u32 i = 0; i < n; i++){
    u32 x;
    std::cin >> x;
    w.push_back(x);
  }
  std::sort(w.begin(), w.end());


  std::priority_queue<std::pair<u64, u32>, std::vector<std::pair<u64, u32> >, std::greater<> > q;

  std::vector<u64> dist(w[0], l+1);

  dist[0] = 0;
  q.emplace(0, 0);
  while(!q.empty()){
    auto [d, v] = q.top();
    q.pop();   
    if(d != dist[v]) continue;
    for(u32 i = 1; i < n; i++){
      u32 u = (v + w[i]) % w[0];
      if(d + w[i] < dist[u]){
        dist[u] = d + w[i];
        q.emplace(dist[u], u);
      }
    }
  }

  u64 ans = l / w[0];
  for(u32 i = 1; i < w[0]; i++){
    if(dist[i] == l+1) continue;
    ans += 1 + (l - dist[i]) / w[0];
  }

  std::cout << ans << std::endl;

  return 0;
}
0