結果

問題 No.1 道のショートカット
ユーザー どららどらら
提出日時 2015-05-30 13:53:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,670 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 77,372 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-27 21:44:23
合計ジャッジ時間 2,418 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define INF 1000000000

vector<int> S, T, Y, M;

int solve(int N, int C){

  bool visited[N+1][C+1];
  int sec[N+1][C+1];
  rep(i,N+1){
    rep(j,C+1){
      sec[i][j] = INF;
      visited[i][j] = false;
    }
  }
  sec[1][0] = 0;

  while(true){
    int minpos, mincost, minsec = INF;
    REP(i,1,N+1){
      rep(j,C+1){
        if(minsec > sec[i][j] && !visited[i][j]){
          minpos = i;
          mincost = j;
          minsec = sec[i][j];
        }
      }
    }
    
    if(minsec == INF) break;
    if(minpos == N) return minsec;
    visited[minpos][mincost] = true;

    rep(i,Y.size()){
      int s = S[i];
      int t = T[i];
      int y = Y[i];
      int m = M[i];
      if(minpos != s) continue;
      if(mincost + y <= C &&
         sec[t][mincost+y] > minsec + m){
        sec[t][mincost+y] = minsec + m;
      }
    }
  }
  return -1;
}

int main(){
  int N, C, V, tmp;

  cin >> N >> C >> V;
  rep(i,V){
    cin >> tmp;
    S.push_back(tmp);
  }
  rep(i,V){
    cin >> tmp;
    T.push_back(tmp);
  }
  rep(i,V){
    cin >> tmp;
    Y.push_back(tmp);
  }
  rep(i,V){
    cin >> tmp;
    M.push_back(tmp);
  }
  
  cout << solve(N, C) << endl;

  return 0;
}
0