結果

問題 No.1782 ManyCoins
ユーザー milanis48663220milanis48663220
提出日時 2021-12-29 11:08:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,597 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 130,908 KB
実行使用メモリ 814,400 KB
最終ジャッジ日時 2024-04-14 16:39:18
合計ジャッジ時間 18,196 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 6 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 211 ms
54,352 KB
testcase_14 AC 1,209 ms
492,824 KB
testcase_15 AC 677 ms
239,272 KB
testcase_16 AC 275 ms
96,564 KB
testcase_17 AC 373 ms
151,200 KB
testcase_18 AC 324 ms
108,548 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 201 ms
81,640 KB
testcase_21 AC 327 ms
132,736 KB
testcase_22 MLE -
testcase_23 MLE -
testcase_24 AC 38 ms
57,848 KB
testcase_25 MLE -
testcase_26 AC 256 ms
91,252 KB
testcase_27 AC 843 ms
404,716 KB
testcase_28 AC 37 ms
57,904 KB
testcase_29 AC 178 ms
120,452 KB
testcase_30 AC 269 ms
151,484 KB
testcase_31 AC 364 ms
198,424 KB
testcase_32 AC 393 ms
214,016 KB
testcase_33 AC 862 ms
487,440 KB
testcase_34 MLE -
testcase_35 MLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
権限があれば一括ダウンロードができます

ソースコード

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 ll INF = 1e+15;

typedef pair<ll, int> P;

struct edge{
    int to;
    ll cost;
};

vector<ll> dijkstra(int s, vector<vector<edge>> G){
    priority_queue<P, vector<P>, greater<P>> que;
    int n = G.size();
    vector<ll> d(n, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        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;
                que.push(P(d[e.to], 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];
    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];
            g[j].push_back(edge{k, w[i]});
        }
    }
    auto d = dijkstra(0, g);
    // print_vector(d);
    ll ans = l;
    for(int i = 1; i < w[0]; i++){
        if(d[i] > l){
            if(l%w[0] >= i) {
                ans -= l/w[0]+1;
            } else {
                ans -= l/w[0];
            }
        }else{
            // debug_value(i)
            ans -= d[i]/w[0];
        }
    }
    cout << ans << endl;
}
0