結果

問題 No.1 道のショートカット
ユーザー naimonon77naimonon77
提出日時 2016-01-14 08:22:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,902 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 69,644 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 21:50:52
合計ジャッジ時間 2,138 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <cstdio>
#include <vector>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int test = 0;
typedef struct root {
  int nextCity;
  int money;
  int time;
}Root;
struct town {
  vector<Root> root;
};

int N,C,V;
int S[1505];
int T[1505];
int Y[1505];
int M[1505];
struct town town[55];
int dp[55][305] = {0};
int main(void)
{
  int i,j,k,l;
  cin >> N >> C >> V;
  /*
  for(i=0;i<20;i++) {
  printf("town[%d].root.size() = %d\n",i,town[i].root.size());
  } */
  rep(i,V) {
    cin >> S[i];
  }
  rep(i,V) {
    cin >> T[i];
  }
  rep(i,V) {
    cin >> Y[i];
  }
  rep(i,V) {
    cin >> M[i];
  }

  rep(i,V) {
    Root tmp = {T[i],Y[i],M[i]};
    town[S[i]].root.push_back(tmp);
  }

  rep(i,C+1) {
    dp[1][i] = INT_MAX;
  }
  dp[1][C] = 0;
  REP(i,2,N+1) {
    rep(l,C+1) {
      dp[i][l] = INT_MAX;
      for(j=0;j<i;j++) {
        if(dp[j][l]== INT_MAX) continue;
        int n = town[j].root.size();
        for(k=0;k<n;k++) {
          if(town[j].root[k].nextCity == i) {
            if(l+1 - town[j].root[k].money > 0
              && dp[i][ l - town[j].root[k].money ]
      > dp[j][l] + town[j].root[k].time) {
        dp[i][ l - town[j].root[k].money ]
        = dp[j][l] + town[j].root[k].time;
      }
          }
        }
      }
    }
  }
  int minMoney = INT_MAX;

  rep(i,C+1) {
    if(minMoney > dp[N][i]) minMoney = dp[N][i];
  }
  if(minMoney == INT_MAX) minMoney = -1;
  printf("%d\n",minMoney);
  /*
  rep(i,N) {
  rep(j,town[i].root.size()) {
  printf("%d",i);
  printf(" %d",town[i].root[j].nextCity);
  printf(" %d",town[i].root[j].money);
  printf(" %d\n",town[i].root[j].time);
  }
  }
  */
  return 0;
}
0