結果
| 問題 |
No.1782 ManyCoins
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-11 17:45:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| コード長 | 1,227 bytes |
| コンパイル時間 | 1,882 ms |
| コンパイル使用メモリ | 201,040 KB |
| 最終ジャッジ日時 | 2025-01-26 07:54:48 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 |
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
constexpr int NMAX = 20;
constexpr int WMAX = 1000000;
constexpr i64 INF = 1LL << 60;
i64 dp[WMAX];
int Ws[NMAX];
int ws[NMAX];
int main()
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int N;
i64 L;
std::cin >> N >> L;
for (int i = 0; i < N; i++) {
std::cin >> Ws[i];
}
std::sort(Ws, Ws + N);
const int W = Ws[0];
for (int i = 1; i < N; i++) {
ws[i] = Ws[i] % W;
}
std::fill(dp, dp + W, INF);
dp[0] = 0;
using P = std::pair<i64, int>;
std::priority_queue<P, std::vector<P>, std::greater<P>> Q;
Q.push({0, 0});
while (not Q.empty()) {
const auto [c, w] = Q.top();
Q.pop();
if (dp[w] < c) { continue; }
for (int i = 1; i < N; i++) {
int nw = (w + ws[i]);
if (nw >= W) { nw -= W; }
const i64 ndp = c + Ws[i];
if (dp[nw] > ndp) {
dp[nw] = ndp;
Q.push({ndp, nw});
}
}
}
i64 ans = 0;
for (int w = 0; w < W; w++) {
if (dp[w] > L) { continue; }
ans += (L - dp[w]) / W + 1;
}
std::cout << ans - 1 << "\n";
return 0;
}