結果

問題 No.1449 新プロランド
ユーザー shiomusubi496shiomusubi496
提出日時 2021-03-24 23:46:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 176,972 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 01:42:18
合計ジャッジ時間 2,429 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:24:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   24 |         auto[c,v,p]=PQ.top();PQ.pop();
      |             ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using A=array<ll,3>;
constexpr ll INF=1e18;
struct edge{
    int to;
    ll cost;
};
bool chmin(ll&a,ll b){return a>b?a=b,true:false;}
vector<edge>G[105];
ll dist[105][1005],T[105];
int main(){
    int N,M; cin>>N>>M;
    for(int i=0;i<M;i++){
        int A,B,C; cin>>A>>B>>C;
        G[A-1].push_back({B-1,C});
        G[B-1].push_back({A-1,C});
    }
    for(int i=0;i<N;i++) cin>>T[i];
    priority_queue<A,vector<A>,greater<A>>PQ; PQ.push({0,0,0});
    fill(dist[0],dist[N],INF); dist[0][0]=0;
    while(!PQ.empty()){
        auto[c,v,p]=PQ.top();PQ.pop();
        if(dist[v][p]<c) continue;
        c+=T[v];p=min(p+T[v],1001ll);
        for(edge e:G[v]){
            if(chmin(dist[e.to][p],c+e.cost/p)) PQ.push({c+e.cost/p,e.to,p});
        }
    }
    ll ans=INF;
    for(int i=0;i<=1001;i++) chmin(ans,dist[N-1][i]);
    cout<<ans<<endl;
}
0