結果

問題 No.1782 ManyCoins
ユーザー SSRSSSRS
提出日時 2021-12-11 00:11:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,652 ms / 2,000 ms
コード長 868 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 175,852 KB
実行使用メモリ 21,308 KB
最終ジャッジ日時 2023-09-26 00:43:24
合計ジャッジ時間 9,473 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 27 ms
6,324 KB
testcase_14 AC 61 ms
5,792 KB
testcase_15 AC 56 ms
4,688 KB
testcase_16 AC 177 ms
6,636 KB
testcase_17 AC 244 ms
13,052 KB
testcase_18 AC 192 ms
6,840 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 79 ms
7,976 KB
testcase_21 AC 38 ms
5,324 KB
testcase_22 AC 135 ms
13,048 KB
testcase_23 AC 505 ms
21,308 KB
testcase_24 AC 6 ms
10,728 KB
testcase_25 AC 7 ms
4,380 KB
testcase_26 AC 228 ms
9,500 KB
testcase_27 AC 7 ms
4,384 KB
testcase_28 AC 5 ms
10,800 KB
testcase_29 AC 38 ms
10,820 KB
testcase_30 AC 46 ms
10,792 KB
testcase_31 AC 77 ms
10,880 KB
testcase_32 AC 108 ms
10,820 KB
testcase_33 AC 596 ms
11,064 KB
testcase_34 AC 1,108 ms
10,716 KB
testcase_35 AC 1,652 ms
10,744 KB
testcase_36 AC 10 ms
4,384 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 1 ms
4,384 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 3 ms
4,424 KB
testcase_41 AC 3 ms
4,732 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 5 ms
9,104 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,384 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 5 ms
10,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000;
int main(){
  int N;
  long long L;
  cin >> N >> L;
  vector<int> W(N);
  for (int i = 0; i < N; i++){
    cin >> W[i];
  }
  sort(W.begin(), W.end());
  vector<long long> dp(W[0], INF);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
  pq.push(make_pair(0, 0));
  while (!pq.empty()){
    long long x = pq.top().first;
    int v = pq.top().second;
    pq.pop();
    if (dp[v] == INF){
      dp[v] = x;
      for (int j = 1; j < N; j++){
        int w = (v + W[j]) % W[0];
        if (dp[w] == INF){
          pq.push(make_pair(x + W[j], w));
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < W[0]; i++){
    if (dp[i] <= L){
      ans += (L - dp[i]) / W[0] + 1;
    }
  }
  cout << ans - 1 << endl;
}
0