結果

問題 No.1 道のショートカット
ユーザー nenuonnenuon
提出日時 2017-08-01 01:04:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 1,431 bytes
コンパイル時間 2,451 ms
コンパイル使用メモリ 93,336 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:09:21
合計ジャッジ時間 2,731 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
const int inf = 1e9;
int N,C,V;
int S[2000],T[2000],Y[2000],M[2000];
struct edge {
  int to, cost, times;
  edge(int a, int b, int c) {
    to = a, cost = b, times = c;
  }
};
vector<vector<edge> > G;
int dp[60][301];

int main()
{
  cin >> N >> C >> V;
  G.resize(N+1);
  FOR(i,0,V) cin >> S[i];
  FOR(i,0,V) cin >> T[i];
  FOR(i,0,V) cin >> Y[i];
  FOR(i,0,V) cin >> M[i];
  G[0].push_back(edge(1,0,0));
  FOR(i,0,V) {
    G[S[i]].push_back(edge(T[i],Y[i],M[i]));
  }
  FOR(i,0,60) FOR(j,0,301) dp[i][j] = inf;
  dp[0][0] = 0;
  // 幅優先で
  queue<int> Q;
  Q.push(0);
  while(!Q.empty()) {
    int v = Q.front();Q.pop();
    for(edge &e : G[v]) {
      bool next = false;
      FOR(i,0,301) {
        if(dp[v][i] == inf) continue;
        if(i + e.cost > 300) continue;
        if(dp[e.to][i + e.cost] > dp[v][i] + e.times) {
          next = true;
          dp[e.to][i + e.cost] = dp[v][i] + e.times;
        }
      }
      if(next) Q.push(e.to);
    }
  }
  int mn = inf;
  FOR(i,1,C+1) {
    mn = min(mn, dp[N][i]);
  }
  cout << (mn == inf ? -1 : mn) << endl;
  return 0;
}
0