結果

問題 No.1 道のショートカット
ユーザー naimonon77
提出日時 2016-01-14 08:22:41
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,902 bytes
コンパイル時間 563 ms
コンパイル使用メモリ 68,380 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:19:12
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

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