結果

問題 No.1 道のショートカット
ユーザー naimonon77naimonon77
提出日時 2016-01-14 08:54:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,602 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 62,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:37:43
合計ジャッジ時間 2,166 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
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 1 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 1 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <limits.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;


int test = 0;
typedef struct root {
  int preCity;
  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 = {S[i],Y[i],M[i]};
    town[T[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;
      int n = town[i].root.size();
      for(k=0;k<n;k++) {
        if(dp[town[i].root[k].preCity][l]== INT_MAX) continue;

        if(l+1 - town[i].root[k].money > 0) {
          dp[i][l] 
          = min(dp[town[i].root[k].preCity][l] + town[i].root[k].time
            ,dp[i][ l - town[i].root[k].money ]);
        }
      }
    }
  }
  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