結果

問題 No.1 道のショートカット
ユーザー togatogatogatoga
提出日時 2015-04-10 20:40:25
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,018 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 91,932 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2023-09-22 12:03:25
合計ジャッジ時間 7,348 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>

#include <tuple>
#include <unordered_map>

#define mp       make_pair
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N;
int C;
int V;
int S[55];
int T[55];
int Y[55];
int M[55];
int dp[55][330];
struct State{
  int tar;
  int mcost;
  int tcost;
  State(int _tar, int _mcost, int _tcost){
    tar = _tar;
    mcost = _mcost;
    tcost = _tcost;
  }
};
vector<State> graph[55];
int memo(int pos, int money){
  // cout << pos << " " << money << endl;
  if (pos == N){

    return 0;
  }
  if (dp[pos][money] < INF){
    return dp[pos][money];
  }
  int res = INF;
  for (int i = 0; i < graph[pos].size(); i++){
    State p = graph[pos][i];
    if (money - p.mcost >= 0){
      res = min(res, memo(p.tar, money - p.mcost) + p.tcost);
    }
  }
  // cout << "res = " << res << endl;
  return dp[pos][money] = res;
}
int main(){
  cin >> N;
  cin >> C;
  cin >> V;
  for (int i = 0; i < V; i++){
    cin >> S[i];
  }
  for (int i = 0; i < V; i++){
    cin >> T[i];
  }
  for (int i = 0; i < V; i++){
    cin >> Y[i];
  }

  for (int i = 0; i < V; i++){
    cin >> M[i];
  }

  for (int i = 0; i < V; i++){
    graph[S[i]].push_back(State(T[i], Y[i], M[i]));
    graph[T[i]].push_back(State(S[i], Y[i], M[i]));
  }

  for (int i = 0; i < 55; i++){
    for (int j = 0; j < 330; j++){
      dp[i][j] = INF;
    }
  }
  int res = memo(1, C);
  if (res != INF){
    cout << res << endl;
  }else{
    cout << - 1 << endl;
  }

  return 0;
}
0