結果

問題 No.1 道のショートカット
ユーザー mint6421mint6421
提出日時 2019-07-01 08:54:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 2,278 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 158,796 KB
実行使用メモリ 11,504 KB
最終ジャッジ日時 2023-09-27 22:20:12
合計ジャッジ時間 2,882 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 11 ms
9,444 KB
testcase_09 AC 7 ms
6,392 KB
testcase_10 AC 5 ms
5,316 KB
testcase_11 AC 7 ms
6,664 KB
testcase_12 AC 16 ms
11,504 KB
testcase_13 AC 14 ms
11,248 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 4 ms
4,436 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,620 KB
testcase_21 AC 4 ms
4,884 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 10 ms
10,068 KB
testcase_24 AC 10 ms
10,636 KB
testcase_25 AC 5 ms
5,936 KB
testcase_26 AC 4 ms
5,188 KB
testcase_27 AC 10 ms
9,096 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 4 ms
4,636 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 9 ms
7,872 KB
testcase_33 AC 6 ms
6,244 KB
testcase_34 AC 9 ms
8,768 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 4 ms
4,560 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:87:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
 main(){
      ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}




template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;




template< typename T >
vector<T> dijkstra(WG<T> &g,int s){
  const auto lim = numeric_limits<T>::max();
  vector<T> dist(g.size(),lim);
  using Pi = pair<T,int>;
  priority_queue<Pi,vector<Pi>,greater<Pi>> q;
  dist[s] = 0;
  q.emplace(dist[s],s);
  while(!q.empty()){
    T cost;
    int idx;
    tie(cost,idx) = q.top();
    q.pop();
    if(dist[idx] < cost) continue;
    for( auto &e : g[idx]){
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      q.emplace(dist[e.to],e.to);
    }
  }
  return dist;
}



main(){
  int n,c,v;
  cin>>n>>c>>v;
  WG<int> es(n*(c+1));
  vector<int> s(v),t(v),y(v),m(v);
  rep(i,v){
    cin>>s[i];
    s[i]--;
  }
  rep(i,v){
    cin>>t[i];
    t[i]--;
  }
  rep(i,v){
    cin>>y[i];
  }
  rep(i,v){
    cin>>m[i];
  }

  rep(i,v){
    FOR(j,0,c-y[i]+1){
      es[s[i]*(c+1)+j+y[i]].PB(edge<int>(t[i]*(c+1)+j,m[i]));
    }
  }

  vector<int> res=dijkstra(es,c);

  int ans=INF;
  rep(i,c+1){
    
    ans=min(ans,res[(n-1)*(c+1)+i]);
  }

  cout<<(ans==INF?-1:ans)<<endl;
}
0