結果

問題 No.1 道のショートカット
ユーザー 久我山菜々久我山菜々
提出日時 2018-09-29 13:54:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,276 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 93,912 KB
実行使用メモリ 11,296 KB
最終ジャッジ日時 2023-09-22 13:23:46
合計ジャッジ時間 7,911 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
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<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;
}

bool less2(std::pair<int, int> lhs, std::pair<int, int> rhs) {
  return (lhs.first < rhs.first) && (lhs.second < rhs.second);
}

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(V), ts(V), ys(V),ms(V);
  for(int i{0}; i < V; ++i) {
    std::cin >> ss[i];
  }
  for(int i{0}; i < V; ++i) {
    std::cin >> ts[i];
  }
  for(int i{0}; i < V; ++i) {
    std::cin >> ys[i];
  }
  for(int i{0}; i < V; ++i) {
    std::cin >> ms[i];
  }

  std::vector<std::pair<int, int>> vcs(V), vs(V);
  for(int i{0}; i < V; ++i) {
    vcs[i] = std::make_pair(ms[i], ys[i]);
    vs[i] = std::make_pair(ss[i] - 1, ts[i] - 1);
  }

  std::sort(begin(vs), end(vs), less);
  // for(auto e: vs) {
  //   std::cout << e.first << ',' << e.second << std::endl;
  // }

  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) {
    auto const _v = vs[i];
    int const s = _v.first;
    int const t = _v.second;

    auto& n = ns[t];
    for(auto c: ns[s]) {
      auto new_cost = plus(c, vcs[i]);
      n.push_back(new_cost);
      auto it = std::remove_if(begin(n), end(n), [C, new_cost](auto x) { return x.second > C; });
      n.erase(it, end(n));
      // for(auto e: n) {
      //   std::cout << e.first << ',' << e.second << std::endl;
      // }
      // std::cout << "#####" << ns[s].size() << std::endl;
    }
    // std::cout << "--------------" << std::endl;
  }

  auto& n = ns[N - 1];
  std::sort(begin(n), end(n), less);
  // for(auto e: n) {
  //   std::cout << e.first << ',' << e.second << std::endl;
  // }
  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