結果

問題 No.2739 Time is money
ユーザー kzyKTkzyKT
提出日時 2024-04-20 13:03:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 1,708 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 168,000 KB
実行使用メモリ 30,036 KB
最終ジャッジ日時 2024-04-20 13:03:40
合計ジャッジ時間 7,903 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 120 ms
18,816 KB
testcase_03 AC 279 ms
26,208 KB
testcase_04 AC 113 ms
18,176 KB
testcase_05 AC 174 ms
19,484 KB
testcase_06 AC 227 ms
25,392 KB
testcase_07 AC 340 ms
28,672 KB
testcase_08 AC 313 ms
29,324 KB
testcase_09 AC 334 ms
29,512 KB
testcase_10 AC 223 ms
28,672 KB
testcase_11 AC 378 ms
29,596 KB
testcase_12 AC 218 ms
26,880 KB
testcase_13 AC 219 ms
26,752 KB
testcase_14 AC 207 ms
26,752 KB
testcase_15 AC 129 ms
28,904 KB
testcase_16 AC 130 ms
25,116 KB
testcase_17 AC 349 ms
30,032 KB
testcase_18 AC 322 ms
30,036 KB
testcase_19 AC 191 ms
27,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ln cout<<'\n'
#define ll long long
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.12f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
typedef pair<P,P> PP;

void Main() {
  ll n,m,t;
  cin >> n >> m >> t;
  vector<PP> v[n];
  rep(i,m) {
    ll x,y,z,w;
    cin >> x >> y >> z >> w;
    x--,y--;
    v[x].pb(PP(P(y,-1),P(z,w)));
    v[y].pb(PP(P(x,-1),P(z,w)));
  }
  priority_queue<PP,vector<PP>,greater<PP>> que;
  que.push(PP(P(0,0),P(0,0)));
  P d[n];
  fill(d,d+n,P(MAXL,MAXL));
  d[0]=P(0,0);
  while(!que.empty()) {
    PP p=que.top();que.pop();
    ll x=p.S.S,c=p.F.F,e=p.F.S,w=p.S.F;
    if(d[x]<P(c,e)) continue;
    rep(i,v[x].size()) {
      ll y=v[x][i].F.F,ww=w+v[x][i].S.S,ee=e+v[x][i].S.F;
      ll cc=ww+(ee+t-1)/t;
      if(d[y]>P(cc,ee)) {
        d[y]=P(cc,ee);
        que.push(PP(P(cc,ee),P(ww,y)));
      }
    }
  }
  ll ans=d[n-1].F;
  if(ans==MAXL) ans=-1;
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0