結果

問題 No.1449 新プロランド
ユーザー rogi52rogi52
提出日時 2022-10-07 21:27:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,566 bytes
コンパイル時間 2,661 ms
コンパイル使用メモリ 211,320 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-08-25 16:54:08
合計ジャッジ時間 3,607 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 27 ms
8,744 KB
testcase_06 AC 17 ms
6,644 KB
testcase_07 AC 10 ms
6,004 KB
testcase_08 AC 18 ms
8,072 KB
testcase_09 AC 11 ms
5,304 KB
testcase_10 AC 12 ms
7,068 KB
testcase_11 AC 8 ms
6,764 KB
testcase_12 AC 16 ms
7,640 KB
testcase_13 AC 12 ms
5,400 KB
testcase_14 AC 8 ms
6,436 KB
testcase_15 AC 19 ms
7,368 KB
testcase_16 AC 12 ms
5,852 KB
testcase_17 AC 13 ms
6,144 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 5 ms
5,484 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 8 ms
6,188 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 13 ms
7,552 KB
testcase_24 AC 9 ms
4,500 KB
testcase_25 WA -
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 27 ms
8,720 KB
testcase_28 AC 17 ms
6,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

// g <- pair < v , cost > 
template < class T >
vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, int s) {
    T INF = numeric_limits< T >::max();
    vector<T> dist(graph.size(), INF);
    priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
    q.push({dist[s] = T(0), s});
    while(!q.empty()){
        auto [uc, ui] = q.top(); q.pop();
        if(uc != dist[ui]) continue;
        for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) 
            q.push({dist[vi] = uc + vc, vi});
    }
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M; cin >> N >> M;
    vector<tuple<int,int,int>> E(M);
    for(auto &[a, b, c] : E) cin >> a >> b >> c, a--, b--;
    vector<int> T(N);
    rep(i,N) cin >> T[i];

    int MAX_C = 1000;
    vector<vector<pair<int,int>>> G(N * (MAX_C + 1));
    auto h = [MAX_C](int v, int p) { return v * (MAX_C + 1) + p; };

    for(auto &[a, b, c] : E) {
        for(int p = 0; p <= MAX_C; p++) {
            if(p + T[a] != 0)
                G[h(a, p)].push_back({h(b, min(MAX_C, p + T[a])), c / min(MAX_C, p + T[a]) + T[a]});
            if(p + T[b] != 0)
                G[h(b, p)].push_back({h(a, min(MAX_C, p + T[b])), c / min(MAX_C, p + T[b]) + T[b]});
        }
    }

    auto dist = dijkstra(G, h(0, 0));
    int ans = numeric_limits<int>::max();
    for(int p = 0; p <= MAX_C; p++) ans = min(ans, dist[h(N - 1, p)]);
    cout << ans << endl;
}
0