結果

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

テストケース

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

ソースコード

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