結果

問題 No.1 道のショートカット
ユーザー 久我山菜々久我山菜々
提出日時 2018-09-29 12:59:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,617 bytes
コンパイル時間 1,054 ms
コンパイル使用メモリ 93,920 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-22 13:22:14
合計ジャッジ時間 7,136 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

bool less(std::pair<int, int> lhs, std::pair<int, int> rhs) {
  if(lhs.first == rhs.first) {
    return lhs.second < rhs.second;
  }
  return lhs.first < rhs.first;
}

std::pair<int, int> plus(std::pair<int, int> lhs, std::pair<int, int> rhs) {
  return std::make_pair(lhs.first + rhs.first, lhs.second + rhs.second);
}

static int const INF{100000000};

int main(int, char**) {
  int N, C, V;
  std::cin >> N >> C >> V;

  std::vector<int> ss(N), ts(N), ys(N),ms(N);
  for(int i{0}; i < N; ++i) {
    std::cin >> ss[i];
  }
  for(int i{0}; i < N; ++i) {
    std::cin >> ts[i];
  }
  for(int i{0}; i < N; ++i) {
    std::cin >> ys[i];
  }
  for(int i{0}; i < N; ++i) {
    std::cin >> ms[i];
  }

  std::vector<std::pair<int, int>> vs(N);
  for(int i{0}; i < N; ++i) {
    vs[i] = std::make_pair(ms[i], ys[i]);
  }

  std::vector<std::vector<std::pair<int, int>>> ns(N, std::vector<std::pair<int, int>>(1, std::make_pair(INF, INF)));
  ns[0] = std::vector<std::pair<int, int>>(1, std::make_pair(0, 0));

  for(int i{0}; i < V; ++i) {
    int const s = ss[i] - 1;
    int const t = ts[i] - 1;

    for(auto c: ns[s]) {
      auto new_cost = plus(c, vs[i]);
      ns[t].push_back(new_cost);
    }

    auto& n = ns[t];
    auto it = std::remove_if(begin(n), end(n), [C](auto x) { return x.second > C; });
    n.erase(it, end(n));
  }

  auto& n = ns[N - 1];
  std::sort(begin(n), end(n), less);
  if(begin(n) == end(n) || n[0].first == INF) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << n[0].first << std::endl;
  }

  return 0;
}
0