結果

問題 No.1 道のショートカット
ユーザー itezpaceitezpace
提出日時 2016-12-07 08:09:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,102 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 66,748 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 12:53:21
合計ジャッジ時間 2,008 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main(){
  int N,C,V;
  cin>>N>>C>>V;
  vector<int> v1(V),v2(V),v3(V),v4(V);
  for(int i=0;i<V;++i){
    cin>>v1[i];
  }
  for(int i=0;i<V;++i){
    cin>>v2[i];
  }
  for(int i=0;i<V;++i){
    cin>>v3[i];
  }
  for(int i=0;i<V;++i){
    cin>>v4[i];
  }
  vector<vector<int>> vv1(N,vector<int>(N));
  vector<pair<int,int>> vp1;
  int a=0;
  for(int i=0;i<V;++i){
    a+=1;
    vv1[v1[i]-1][v2[i]-1]=a;
    vp1.push_back(make_pair(v3[i],v4[i]));
  }
  vector<vector<int>> vv2(C+1,vector<int>(N,INT_MAX));
  vv2[0][0]=0;
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      if(vv1[i][j]){
        for(int k=0;k<C+1;++k){
          if(vv2[k][i]!=INT_MAX){
            int b=k+vp1[vv1[i][j]-1].first;
            int c=vv2[k][i]+vp1[vv1[i][j]-1].second;
            if(b>C) continue;
            if(vv2[b][j]>c) vv2[b][j]=c;
          }
        }
      }
    }
  }
  int x=INT_MAX;
  for(int i=1;i<C+1;++i){
    if(x>vv2[i][N-1]) x=vv2[i][N-1];
  }
  if(x==INT_MAX){
    cout<<-1<<endl;
  } else {
    cout<<x<<endl;
  }
}
0