結果

問題 No.1 道のショートカット
ユーザー ChanyuhChanyuh
提出日時 2019-10-02 21:19:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 2,382 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 115,240 KB
実行使用メモリ 9,292 KB
最終ジャッジ日時 2023-09-27 22:22:40
合計ジャッジ時間 2,401 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 9 ms
7,636 KB
testcase_09 AC 5 ms
5,560 KB
testcase_10 AC 4 ms
4,724 KB
testcase_11 AC 5 ms
5,680 KB
testcase_12 AC 12 ms
9,292 KB
testcase_13 AC 11 ms
9,012 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 4 ms
4,536 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 4 ms
4,644 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 7 ms
7,836 KB
testcase_24 AC 8 ms
8,356 KB
testcase_25 AC 4 ms
5,372 KB
testcase_26 AC 4 ms
4,720 KB
testcase_27 AC 8 ms
7,224 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 7 ms
6,500 KB
testcase_33 AC 5 ms
5,652 KB
testcase_34 AC 6 ms
6,800 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<ll,int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;


template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<T,int>>> & G){
    const T inf=numeric_limits<T>::max();
    using edge=pair<T,int>;
    priority_queue<edge, vector<edge>, greater<edge> > que;
    int n=G.size();
    vector<T> d(n,inf);
    vector<int> b(n,-1);
    d[s]=0;
    que.emplace(d[s],s);
    while (!que.empty()){
        edge p = que.top(); que.pop();
        int v = p.second;
        if (d[v]<p.first) continue;
        for(auto& e:G[v]){
            int u=e.second;
            T c=e.first;
            if (d[u]>d[v]+c){
                d[u]=d[v]+c;
                b[u]=v;
                que.emplace(d[u],u);
            }
        }
    }
    return d;
}

int n,c,v;
int s[1510],t[1510],y[1510],m[1510];
vector<vector<P>> G;

void solve(){
    cin >> n >> c >> v;
    G.resize((c+1)*n,{});
    rep(i,v) cin >> s[i];
    rep(i,v) cin >> t[i];
    rep(i,v) cin >> y[i];
    rep(i,v) cin >> m[i];
    rep(i,v){
        s[i]--;t[i]--;
        rep(k,c-y[i]+1){
            G[s[i]*(c+1)+k].push_back(P(m[i],t[i]*(c+1)+k+y[i]));
        }
    }
    vector<ll> d=dijkstra(0,G);
    ll ans=INF;
    rep(i,c+1){
        //cout << k << " " << i << " " << d[k*(c+1)+i] << endl;
        ans=min(ans,d[(n-1)*(c+1)+i]);
    }
    if (ans==INF) cout << -1 << endl;
    else cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
0