結果

問題 No.1782 ManyCoins
ユーザー KudeKude
提出日時 2021-12-11 03:06:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,240 ms / 2,000 ms
コード長 2,003 bytes
コンパイル時間 3,041 ms
コンパイル使用メモリ 240,104 KB
実行使用メモリ 475,752 KB
最終ジャッジ日時 2023-09-26 07:09:32
合計ジャッジ時間 20,540 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 5 ms
4,788 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 455 ms
114,236 KB
testcase_14 AC 811 ms
283,136 KB
testcase_15 AC 401 ms
143,644 KB
testcase_16 AC 481 ms
175,296 KB
testcase_17 AC 822 ms
290,308 KB
testcase_18 AC 577 ms
196,260 KB
testcase_19 AC 3 ms
4,684 KB
testcase_20 AC 690 ms
253,920 KB
testcase_21 AC 846 ms
304,316 KB
testcase_22 AC 1,240 ms
468,868 KB
testcase_23 AC 977 ms
428,708 KB
testcase_24 AC 28 ms
53,816 KB
testcase_25 AC 1,015 ms
459,900 KB
testcase_26 AC 350 ms
131,132 KB
testcase_27 AC 1,011 ms
469,592 KB
testcase_28 AC 29 ms
53,832 KB
testcase_29 AC 187 ms
116,384 KB
testcase_30 AC 210 ms
116,516 KB
testcase_31 AC 253 ms
132,088 KB
testcase_32 AC 268 ms
147,548 KB
testcase_33 AC 483 ms
272,608 KB
testcase_34 AC 574 ms
319,528 KB
testcase_35 AC 749 ms
475,752 KB
testcase_36 AC 316 ms
168,828 KB
testcase_37 AC 310 ms
183,128 KB
testcase_38 AC 506 ms
334,660 KB
testcase_39 AC 71 ms
43,112 KB
testcase_40 AC 296 ms
171,960 KB
testcase_41 AC 190 ms
112,512 KB
testcase_42 AC 305 ms
176,464 KB
testcase_43 AC 25 ms
40,828 KB
testcase_44 AC 692 ms
449,292 KB
testcase_45 AC 196 ms
113,108 KB
testcase_46 AC 54 ms
17,972 KB
testcase_47 AC 59 ms
18,284 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 30 ms
54,052 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(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