結果

問題 No.1782 ManyCoins
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2021-12-11 21:10:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 89,436 KB
実行使用メモリ 10,876 KB
最終ジャッジ日時 2023-09-27 09:54:29
合計ジャッジ時間 3,661 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 9 ms
6,520 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 32 ms
5,404 KB
testcase_17 AC 36 ms
6,456 KB
testcase_18 AC 39 ms
5,748 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 14 ms
4,428 KB
testcase_21 AC 7 ms
4,376 KB
testcase_22 AC 17 ms
4,652 KB
testcase_23 AC 49 ms
6,748 KB
testcase_24 AC 5 ms
10,716 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 41 ms
5,760 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 6 ms
10,648 KB
testcase_29 AC 24 ms
10,764 KB
testcase_30 AC 5 ms
10,808 KB
testcase_31 AC 20 ms
10,652 KB
testcase_32 AC 26 ms
10,716 KB
testcase_33 AC 59 ms
10,800 KB
testcase_34 AC 10 ms
10,728 KB
testcase_35 AC 8 ms
10,876 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,700 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 5 ms
9,052 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 5 ms
10,652 KB
権限があれば一括ダウンロードができます

ソースコード

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