結果

問題 No.1 道のショートカット
ユーザー obaoba
提出日時 2014-12-22 14:58:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,139 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 85,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:37:22
合計ジャッジ時間 2,318 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

#define REP(a, b) for(int a=0; a<(int)b; a++)

using namespace std;

int main(){
  int N, C, V;
  vector <int> S, T, Y, M;
  map <int, map<int, vector<pair<int, int> > > > keiro; 
  
  cin >> N >> C >> V;
  S.resize(V);
  T.resize(V);
  Y.resize(V);
  M.resize(V);
  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)
	keiro[S[i]][T[i]].push_back(pair<int, int>(Y[i], M[i]));

  int A[N+1][C+1];
  REP(i, N+1){
	REP(j, C+1){
	  A[i][j] = 0;
	}
  }
  
  for(int i=1; i<N; i++){
	for(int j=i+1; j<=N; j++){
	  if(keiro[i].find(j) != keiro[i].end()){
		REP(l, keiro[i][j].size()){
		  int money = keiro[i][j][l].first, time = keiro[i][j][l].second;
		  for(int k=0; k <= (C-money); k++){
			if(A[i][k+money]==0 && i!=1) break;
			A[j][k] = (A[j][k]==0)? A[i][k+money]+time : min(A[j][k], A[i][k+money]+time);
		  }
		}
	  }
	}
  }
  
  int min_time = -1;
  REP(i, C+1){
	if(A[N][i]==0) continue;
	min_time = (min_time==-1) ? A[N][i] : min(A[N][i], min_time);
  }
	
  cout << min_time << endl;

  return 0;
}
0