結果

問題 No.1782 ManyCoins
ユーザー KudeKude
提出日時 2021-12-11 03:08:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 884 ms / 2,000 ms
コード長 2,010 bytes
コンパイル時間 2,693 ms
コンパイル使用メモリ 238,444 KB
実行使用メモリ 297,504 KB
最終ジャッジ日時 2023-09-26 07:15:25
合計ジャッジ時間 17,127 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 338 ms
60,380 KB
testcase_14 AC 651 ms
169,488 KB
testcase_15 AC 314 ms
81,264 KB
testcase_16 AC 373 ms
98,812 KB
testcase_17 AC 653 ms
173,568 KB
testcase_18 AC 447 ms
110,436 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 565 ms
151,952 KB
testcase_21 AC 662 ms
173,072 KB
testcase_22 AC 884 ms
294,264 KB
testcase_23 AC 797 ms
268,664 KB
testcase_24 AC 15 ms
30,404 KB
testcase_25 AC 856 ms
297,504 KB
testcase_26 AC 290 ms
74,036 KB
testcase_27 AC 827 ms
293,852 KB
testcase_28 AC 16 ms
30,348 KB
testcase_29 AC 109 ms
61,760 KB
testcase_30 AC 137 ms
61,748 KB
testcase_31 AC 185 ms
77,344 KB
testcase_32 AC 185 ms
77,208 KB
testcase_33 AC 368 ms
170,952 KB
testcase_34 AC 385 ms
170,988 KB
testcase_35 AC 547 ms
296,004 KB
testcase_36 AC 227 ms
102,736 KB
testcase_37 AC 212 ms
102,492 KB
testcase_38 AC 326 ms
170,712 KB
testcase_39 AC 47 ms
23,700 KB
testcase_40 AC 208 ms
104,248 KB
testcase_41 AC 121 ms
59,400 KB
testcase_42 AC 202 ms
98,672 KB
testcase_43 AC 12 ms
23,480 KB
testcase_44 AC 458 ms
289,220 KB
testcase_45 AC 139 ms
66,264 KB
testcase_46 AC 45 ms
11,024 KB
testcase_47 AC 43 ms
10,824 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 15 ms
30,344 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>;

constexpr int INF = 1001001001;
template <class T, int k = 2>
vector<int> kBFS(const vector<vector<pair<int, T>>>& g, int s = 0) {
  const int n = g.size();
  vector<int> dist(n, INF);
  deque<vector<int>> q(k);
  dist[s] = 0;
  q[0].emplace_back(s);
  for (int dist_cur = 0;;) {
    vector<int>& vs = q[0];
    while (!vs.empty()) {
      int u = vs.back();
      vs.pop_back();
      if (dist[u] != dist_cur) continue;
      for (auto [v, c] : g[u]) {
        int nd = dist_cur + c;
        if (nd < dist[v]) {
          dist[v] = nd;
          q[c].emplace_back(v);
        }
      }
    }
    for(int i = 1;; i++) {
      dist_cur++;
      vector<int> tmp = move(q.front());
      q.pop_front();
      q.emplace_back(move(tmp));
      if (!q[0].empty()) break;
      if (i == k - 1) return dist;
    }
  }
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll l;
  cin >> n >> l;
  VI w(n);
  rep(i, n) cin >> w[i];
  sort(all(w));
  const int m = w.back();
  w.pop_back();
  vector<vector<pair<int, bool>>> g(m);
  rep(u, m) for(int d: w) {
    int v = u + d;
    if (v < m) g[u].emplace_back(v, 0);
    else g[u].emplace_back(v - m, 1);
  }
  auto dist = kBFS(g);
  ll ans = 0;
  rep(i, m) {
    ll d = (ll)dist[i] * m + i;
    if (d > l) continue;
    ans += (l - d) / m + 1;
  }
  ans--;
  cout << ans << '\n';
}
0