結果

問題 No.1 道のショートカット
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-10-26 22:53:29
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,330 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 52,276 KB
最終ジャッジ日時 2024-04-27 02:13:40
合計ジャッジ時間 789 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:12:1: error: ‘vector’ does not name a type
   12 | vector<int> S, T, Y, M;
      | ^~~~~~
main.cpp:13:1: error: ‘vector’ does not name a type
   13 | vector<vector<Route>> routes;
      | ^~~~~~
main.cpp:14:1: error: ‘vector’ does not name a type
   14 | vector<vector<int>> dp;
      | ^~~~~~
main.cpp: In function ‘int main()’:
main.cpp:18:3: error: ‘S’ was not declared in this scope
   18 |   S.resize(V);
      |   ^
main.cpp:19:3: error: ‘T’ was not declared in this scope
   19 |   T.resize(V);
      |   ^
main.cpp:20:3: error: ‘Y’ was not declared in this scope
   20 |   Y.resize(V);
      |   ^
main.cpp:21:3: error: ‘M’ was not declared in this scope
   21 |   M.resize(V);
      |   ^
main.cpp:22:3: error: ‘routes’ was not declared in this scope; did you mean ‘Route’?
   22 |   routes.resize(N);
      |   ^~~~~~
      |   Route
main.cpp:28:56: error: no matching function for call to ‘Route::Route(<brace-enclosed initializer list>)’
   28 |     routes[--S[i]].push_back(Route({--T[i], Y[i], M[i]}));
      |                                                        ^
main.cpp:8:8: note: candidate: ‘Route::Route()’
    8 | struct Route { int to, cost, time; };
      |        ^~~~~
main.cpp:8:8: note:   candidate expects 0 arguments, 1 provided
main.cpp:8:8: note: candidate: ‘constexpr Route::Route(const Route&)’
main.cpp:8:8: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const Route&’
main.cpp:8:8: note: candidate: ‘constexpr Route::Route(Route&&)’
main.cpp:8:8: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘Route&&’
main.cpp:30:3: error: ‘dp’ was not declared in this scope
   30 |   dp.assign(N, vector<int>(C+1, inf));
      |   ^~
main.cpp:30:16: error: ‘vector’ was not declared in this scope
   30 |   dp.assign(N, vector<int>(C+1, inf));
      |                ^~~~~~
main.cpp:3:1: note: ‘std::ve

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

struct Route { int to, cost, time; };

const int inf = 987654321;
int N, C, V;
vector<int> S, T, Y, M;
vector<vector<Route>> routes;
vector<vector<int>> dp;

int main(void) {
  scanf("%d%d%d", &N, &C, &V);
  S.resize(V);
  T.resize(V);
  Y.resize(V);
  M.resize(V);
  routes.resize(N);
  for(int i : range(V)) { scanf("%d", &S[i]); }
  for(int i : range(V)) { scanf("%d", &T[i]); }
  for(int i : range(V)) { scanf("%d", &Y[i]); }
  for(int i : range(V)) { scanf("%d", &M[i]); }
  for(int i : range(V)) {
    routes[--S[i]].push_back(Route({--T[i], Y[i], M[i]}));
  }
  dp.assign(N, vector<int>(C+1, inf));
  dp[0][0] = 0;
  for(int v : range(N)) {
    for(int cost : range(C+1)) {
      for(Route route : routes[v]) {
        int ncost = cost + route.cost;
        if(ncost > C) { continue; }
        dp[route.to][ncost] = min(dp[route.to][ncost], dp[v][cost] + route.time);
      }
    }
  }
  int res = *min_element(dp[N-1].begin(), dp[N-1].end());
  if(res == inf) { res = -1; }
  printf("%d\n", res);
  return 0;
}
0