結果

問題 No.1782 ManyCoins
ユーザー milanis48663220milanis48663220
提出日時 2021-12-29 11:24:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,470 ms / 2,000 ms
コード長 2,664 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 130,608 KB
実行使用メモリ 483,624 KB
最終ジャッジ日時 2024-04-14 16:55:05
合計ジャッジ時間 21,304 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 5 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,948 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 372 ms
114,188 KB
testcase_14 AC 893 ms
281,148 KB
testcase_15 AC 436 ms
142,452 KB
testcase_16 AC 515 ms
174,216 KB
testcase_17 AC 886 ms
288,816 KB
testcase_18 AC 612 ms
195,420 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 821 ms
253,552 KB
testcase_21 AC 965 ms
302,296 KB
testcase_22 AC 1,362 ms
475,220 KB
testcase_23 AC 1,168 ms
433,316 KB
testcase_24 AC 37 ms
53,840 KB
testcase_25 AC 1,315 ms
464,616 KB
testcase_26 AC 395 ms
130,684 KB
testcase_27 AC 1,470 ms
476,232 KB
testcase_28 AC 37 ms
53,840 KB
testcase_29 AC 159 ms
116,364 KB
testcase_30 AC 201 ms
116,520 KB
testcase_31 AC 265 ms
131,956 KB
testcase_32 AC 289 ms
147,768 KB
testcase_33 AC 576 ms
272,752 KB
testcase_34 AC 733 ms
319,516 KB
testcase_35 AC 1,057 ms
483,624 KB
testcase_36 AC 362 ms
168,832 KB
testcase_37 AC 376 ms
183,072 KB
testcase_38 AC 721 ms
334,820 KB
testcase_39 AC 82 ms
43,284 KB
testcase_40 AC 347 ms
172,156 KB
testcase_41 AC 214 ms
112,716 KB
testcase_42 AC 348 ms
176,572 KB
testcase_43 AC 29 ms
41,020 KB
testcase_44 AC 907 ms
456,964 KB
testcase_45 AC 224 ms
113,164 KB
testcase_46 AC 54 ms
18,300 KB
testcase_47 AC 52 ms
18,244 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 37 ms
53,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const int INF = 1e+9;

struct edge{
    int to;
    int cost;
};

vector<int> dijkstra(int s, vector<vector<edge>> G){
    deque<int> dq;
    int n = G.size();
    vector<int> d(n, INF);
    d[s] = 0;
    dq.push_back(s);
    while(!dq.empty()){
        int v = dq.front(); dq.pop_front();
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                if(e.cost == 0) dq.push_front(e.to);
                else dq.push_back(e.to);
            }
        }
    }
    return d;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; ll l; cin >> n >> l;
    vector<int> w(n);
    for(int i = 0; i < n; i++) cin >> w[i];
    sort(w.begin(), w.end(), greater<int>());
    vector<vector<edge>> g(w[0]);
    for(int i = 1; i < n; i++){
        for(int j = 0; j < w[0]; j++){
            int k = (j+w[i])%w[0];
            int cost = k > j ? 0 : 1;
            g[j].push_back(edge{k, cost});
        }
    }
    auto d = dijkstra(0, g);
    // print_vector(d);
    ll ans = l;
    for(int i = 1; i < w[0]; i++){
        if((ll)i+(ll)d[i]*(ll)w[0] > l){
            // debug_value(i)
            if(l%w[0] >= i) {
                ans -= l/w[0]+1;
            } else {
                ans -= l/w[0];
            }
        }else{
            // debug_value(i)
            ans -= d[i];
        }
    }
    cout << ans << endl;
}
0