結果

問題 No.1 道のショートカット
ユーザー cympfhcympfh
提出日時 2015-12-04 14:57:04
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,418 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 163,244 KB
実行使用メモリ 7,576 KB
最終ジャッジ日時 2023-09-22 12:32:59
合計ジャッジ時間 12,026 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,384 KB
testcase_11 AC 3,507 ms
4,384 KB
testcase_12 AC 19 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 RE -
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define all(v) begin(v),end(v)
#define pb push_back
#define inf (1e9)
#define eps (1e-9)
using Integer = long long;
using Real = long double;
const Real PI = acosl(-1);
using P = pair<int, int>;

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T> inline
ostream& operator<<(ostream&os, tuple<S,T> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, set<T> v) {
  os << "(set";
  for (T item: v) os << ' ' << item;
  os << ")";
  return os;
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

//           ^   >  v   <
int dx[] = { -1, 0, 1,  0 };
int dy[] = {  0, 1, 0, -1 };

using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;

int main() {

  int n, c, v; cin >> n >> c >> v;
  vi ss(v), ts(v), ys(v), ms(v);
  cin >> ss >> ts >> ys >> ms;

  using Edge = tuple<int, int, int>;
  vector<vector<Edge>> neigh(v);

  rep (i, v) {
    neigh[ss[i]-1].push_back(make_tuple( ts[i]-1, ys[i], ms[i] ));
  }

  using Time = int;
  Time table[303][n];

  rep (c, 303) rep (i, n) table[c][i] = inf;
  table[c][0] = 0;

  stack<tuple<int, int>> s;
  s.push(make_tuple(c, 0));

  while (not s.empty()) {
    int c, u;
    tie(c, u) = s.top(); s.pop();
    for (Edge&e: neigh[u]) {
      int v, y, m;
      tie(v,y,m) = e;
      if (c - y < 0) continue;
      table[c-y][v] = min(table[c-y][v], table[c][u] + m);
      s.push(make_tuple(c-y, v));
    }
  }

  Time ans = inf;
  rep (k, c+1) {
    if (table[k][n-1] == inf) continue;
    ans = min(ans, table[k][n-1]);
  }
  cout<<(ans<inf?ans:-1)<< endl;

  return 0;
}
0