結果

問題 No.1782 ManyCoins
ユーザー KudeKude
提出日時 2021-12-11 02:31:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 2,788 ms
コンパイル使用メモリ 229,048 KB
実行使用メモリ 28,048 KB
最終ジャッジ日時 2023-09-26 06:25:19
合計ジャッジ時間 8,388 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 29 ms
11,028 KB
testcase_14 AC 284 ms
18,848 KB
testcase_15 AC 140 ms
15,464 KB
testcase_16 AC 183 ms
15,456 KB
testcase_17 AC 293 ms
20,060 KB
testcase_18 AC 209 ms
15,528 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 235 ms
19,720 KB
testcase_21 AC 281 ms
20,240 KB
testcase_22 AC 353 ms
27,912 KB
testcase_23 AC 304 ms
19,288 KB
testcase_24 AC 7 ms
11,240 KB
testcase_25 AC 333 ms
28,048 KB
testcase_26 AC 128 ms
11,236 KB
testcase_27 AC 330 ms
27,724 KB
testcase_28 AC 7 ms
11,344 KB
testcase_29 AC 22 ms
11,252 KB
testcase_30 AC 21 ms
11,388 KB
testcase_31 AC 29 ms
11,244 KB
testcase_32 AC 33 ms
11,168 KB
testcase_33 AC 45 ms
11,184 KB
testcase_34 AC 44 ms
11,196 KB
testcase_35 AC 53 ms
11,256 KB
testcase_36 AC 27 ms
11,000 KB
testcase_37 AC 9 ms
10,892 KB
testcase_38 AC 7 ms
11,232 KB
testcase_39 AC 4 ms
7,680 KB
testcase_40 AC 7 ms
10,904 KB
testcase_41 AC 5 ms
9,556 KB
testcase_42 AC 6 ms
10,524 KB
testcase_43 AC 5 ms
9,604 KB
testcase_44 AC 7 ms
11,244 KB
testcase_45 AC 6 ms
10,092 KB
testcase_46 AC 10 ms
4,404 KB
testcase_47 AC 10 ms
4,480 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 7 ms
11,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<class T> void chmin(T& a, const T& b) { a = min(a, b); }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int w[20];
ll dist[1000000];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll l;
  cin >> n >> l;
  rep(i, n) cin >> w[i];
  sort(w, w + n);
  int m = w[n - 1];
  n--;
  constexpr ll INF = 1002003004005006007;
  rep(i, m) dist[i] = INF;
  auto cmp = [&](const pair<int, ll>& lhs, const pair<int, ll>& rhs) {
    return lhs.second > rhs.second;
  };
  priority_queue<
      pair<int, ll>,
      vector<pair<int, ll>>,
      decltype(cmp)
      > q(cmp);
  auto push = [&](int v, ll d) {
    if (d < dist[v]) {
      dist[v] = d;
      q.emplace(v, d);
    }
  };
  push(0, 0);
  while(!q.empty()) {
    auto [u, d] = q.top(); q.pop();
    if (dist[u] != d) continue;
    rep(i, n) {
      int v = u + w[i];
      ll nd = d + w[i];
      if (v >= m) v -= m;
      push(v, nd);
    }
  }
  ll ans = 0;
  rep(i, m) {
    if (dist[i] > l) continue;
    // dist[i] + (cnt-1)m <= l
    // cnt <= (l - dist[i]) / m + 1
    ans += (l - dist[i]) / m + 1;
  }
  ans--;  // k = 0
  cout << ans << '\n';
}
0