結果

問題 No.1782 ManyCoins
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-07-25 21:07:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 202,400 KB
実行使用メモリ 29,200 KB
最終ジャッジ日時 2024-04-10 12:35:41
合計ジャッジ時間 7,910 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,360 KB
testcase_01 AC 5 ms
11,352 KB
testcase_02 AC 5 ms
11,332 KB
testcase_03 AC 5 ms
11,292 KB
testcase_04 AC 5 ms
11,560 KB
testcase_05 AC 5 ms
11,336 KB
testcase_06 AC 5 ms
11,268 KB
testcase_07 AC 6 ms
11,460 KB
testcase_08 AC 5 ms
11,368 KB
testcase_09 AC 5 ms
11,464 KB
testcase_10 AC 5 ms
11,256 KB
testcase_11 AC 5 ms
11,352 KB
testcase_12 AC 5 ms
11,244 KB
testcase_13 AC 73 ms
11,232 KB
testcase_14 AC 331 ms
19,908 KB
testcase_15 AC 165 ms
17,108 KB
testcase_16 AC 218 ms
15,572 KB
testcase_17 AC 314 ms
19,564 KB
testcase_18 AC 230 ms
15,448 KB
testcase_19 AC 5 ms
11,496 KB
testcase_20 AC 271 ms
20,752 KB
testcase_21 AC 334 ms
19,420 KB
testcase_22 AC 416 ms
27,868 KB
testcase_23 AC 352 ms
19,632 KB
testcase_24 AC 15 ms
11,416 KB
testcase_25 AC 403 ms
28,212 KB
testcase_26 AC 149 ms
13,268 KB
testcase_27 AC 385 ms
29,200 KB
testcase_28 AC 15 ms
11,388 KB
testcase_29 AC 37 ms
11,468 KB
testcase_30 AC 17 ms
11,416 KB
testcase_31 AC 31 ms
11,388 KB
testcase_32 AC 39 ms
11,260 KB
testcase_33 AC 70 ms
11,396 KB
testcase_34 AC 20 ms
11,468 KB
testcase_35 AC 18 ms
11,428 KB
testcase_36 AC 33 ms
11,600 KB
testcase_37 AC 18 ms
11,612 KB
testcase_38 AC 15 ms
11,520 KB
testcase_39 AC 8 ms
11,464 KB
testcase_40 AC 15 ms
11,256 KB
testcase_41 AC 12 ms
11,284 KB
testcase_42 AC 14 ms
11,376 KB
testcase_43 AC 12 ms
11,420 KB
testcase_44 AC 15 ms
11,584 KB
testcase_45 AC 14 ms
11,584 KB
testcase_46 AC 6 ms
11,348 KB
testcase_47 AC 7 ms
11,464 KB
testcase_48 AC 5 ms
11,376 KB
testcase_49 AC 4 ms
11,240 KB
testcase_50 AC 15 ms
11,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
using pli = pair<i64, int>;

i64 L, dis[1000000];

int n, w[22];

int main() {
    cin >> n >> L;
    for(int i = 0; i < n; i ++)
        cin >> w[i];
    sort(w, w + n);
    fill(dis + 1, dis + 1000000, L + 1);
    priority_queue<pli, vector<pli>, greater<pli> > pq;
    pq.push({dis[0], 0});
    while(pq.size()) {
        auto [d, u] = pq.top();
        pq.pop();
        if(dis[u] < d) continue;

        for(int i = 0; i < n - 1; i ++) {
            int v = (u + w[i]) % w[n - 1];
            if(d + w[i] < dis[v]) {
                dis[v] = d + w[i];
                pq.push({dis[v], v});
            }
        }
    }

    i64 ans = -1;

    for(int i = 0; i < w[n - 1]; i ++)
        ans += (L - dis[i] + w[n - 1]) / w[n - 1];

    cout << ans;
}
0