結果

問題 No.1 道のショートカット
ユーザー nenuonnenuon
提出日時 2017-08-01 00:55:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,377 ms / 5,000 ms
コード長 1,371 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 89,024 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:09:36
合計ジャッジ時間 13,938 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 20 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 380 ms
4,376 KB
testcase_11 AC 1,215 ms
4,376 KB
testcase_12 AC 181 ms
4,376 KB
testcase_13 AC 173 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2,266 ms
4,376 KB
testcase_24 AC 1,654 ms
4,376 KB
testcase_25 AC 52 ms
4,376 KB
testcase_26 AC 16 ms
4,380 KB
testcase_27 AC 1,074 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2,377 ms
4,380 KB
testcase_30 AC 89 ms
4,376 KB
testcase_31 AC 175 ms
4,380 KB
testcase_32 AC 56 ms
4,380 KB
testcase_33 AC 30 ms
4,376 KB
testcase_34 AC 768 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 957 ms
4,376 KB
testcase_37 AC 225 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 49 ms
4,376 KB
testcase_41 AC 4 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 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];

void dfs(int v, int par) {
  for(edge &e : G[v]) {
    if(e.to == par) continue;
    bool next = false;
    FOR(i,0,301) {
      if(dp[v][i] == inf) continue;
      if(dp[e.to][i + e.cost] > dp[v][i] + e.times && i + e.cost <= 300) {
        next = true;
        dp[e.to][i + e.cost] = dp[v][i] + e.times;
      }
    }
    if(next) dfs(e.to, v);
  }
  return;
}
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;
  dfs(0, -1);
  int mn = inf;
  FOR(i,1,C+1) {
    mn = min(mn, dp[N][i]);
  }
  cout << (mn == inf ? -1 : mn) << endl;
  return 0;
}
0