結果
| 問題 |
No.1782 ManyCoins
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-11 17:00:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 108 ms / 2,000 ms |
| コード長 | 1,659 bytes |
| コンパイル時間 | 1,936 ms |
| コンパイル使用メモリ | 195,608 KB |
| 最終ジャッジ日時 | 2025-01-26 07:54:28 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 |
ソースコード
#include <bits/stdc++.h>
constexpr int NMAX = 20;
constexpr int WMAX = 1000000;
struct Deq
{
Deq() {}
int front() const
{
return BUF[head];
}
bool isEmpty() const
{
return (head == tail);
}
void pushFront(int v)
{
BUF[--head] = v;
}
void pushBack(int v)
{
BUF[tail++] = v;
}
void popFront()
{
head++;
}
int BUF[2 * WMAX + 1];
int head = WMAX, tail = WMAX;
};
constexpr int INF = 1 << 30;
int dp[WMAX];
int Ws[NMAX];
int main()
{
using i64 = long long;
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, std::greater<int>{});
const int W = Ws[0];
std::fill(dp, dp + W, INF);
dp[0] = 0;
Deq Q;
Q.pushFront(0);
while (not Q.isEmpty()) {
const int w = Q.front();
Q.popFront();
for (int i = 1; i < N; i++) {
int nw = w + Ws[i];
if (nw >= W) {
nw -= W;
if (dp[nw] > dp[w] + 1) {
dp[nw] = dp[w] + 1;
Q.pushBack(nw);
}
} else {
if (dp[nw] > dp[w]) {
dp[nw] = dp[w];
Q.pushFront(nw);
}
}
}
}
i64 ans = 0;
for (int w = 0; w < W; w++) {
if (w > L) { break; }
const i64 l = (L - w) / W;
if (l < dp[w]) { continue; }
ans += l - dp[w] + 1;
}
std::cout << ans - 1 << "\n";
return 0;
}