結果

問題 No.1 道のショートカット
ユーザー どららどらら
提出日時 2015-05-30 13:21:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,778 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 77,824 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:16:44
合計ジャッジ時間 2,415 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 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 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
4,376 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 2 ms
4,376 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int solve(int, int)’:
main.cpp:51:5: warning: ‘minpos’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     if(minpos == N) return minsec;
     ^~

ソースコード

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

int Y[55][55];
int M[55][55];

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(minpos == N) return minsec;
    if(minsec == INF) break;
    visited[minpos][mincost] = true;

    REP(i,1,N+1){
      if(mincost + Y[minpos][i] <= C &&
         sec[i][mincost+Y[minpos][i]] > sec[minpos][mincost] + M[minpos][i]){
        sec[i][mincost+Y[minpos][i]] = sec[minpos][mincost] + M[minpos][i];
      }
    }
  }
  return -1;
}

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

  rep(i,55) rep(j,55){
    Y[i][j] = INF;
    M[i][j] = INF;
  }
  
  cin >> N >> C >> V;
  vector<int> S, T;
  rep(i,V){
    cin >> tmp;
    S.push_back(tmp);
  }
  rep(i,V){
    cin >> tmp;
    T.push_back(tmp);
  }
  rep(i,V){
    cin >> tmp;
    Y[S[i]][T[i]] = min(Y[S[i]][T[i]], tmp);
  }
  rep(i,V){
    cin >> tmp;
    M[S[i]][T[i]] = min(M[S[i]][T[i]], tmp);
  }
  
  cout << solve(N, C) << endl;

  return 0;
}
0