結果

問題 No.1 道のショートカット
ユーザー kk
提出日時 2014-10-27 09:46:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,582 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 71,300 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 11:44:28
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,384 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 1 ms
4,376 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:18: warning: iteration 301 invokes undefined behavior [-Waggressive-loop-optimizations]
       memo[i][j] = INF;
                  ^
main.cpp:52:23: note: within this loop
     for (int j = 0; j <= 301; j++) {
                     ~~^~~~~~

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

int memo[50][301];
int ygraph[50][50];
int mgraph[50][50];
int n, c;
int ans;

#define INF 1000000000

int rec(int i, int j, int k) {
  if (j < 0) return INF;
  if (i == n-1) {
    ans = min(k, ans);
    return ans;
  }
  if (memo[i][j] != INF) {
    if (memo[i][j] > k) {
      memo[i][j] = k;
    }else {
      return memo[i][j];
    }
  }
  //  cout << i << " " << j << " " << k << endl;

  int ret = INF;
  for (int p = i+1; p < n; p++) {
    if (!ygraph[i][p]) continue;
    ret = min(ret, rec(p, j-ygraph[i][p], k+mgraph[i][p]));
  }

  return memo[i][j]=ret;
}

int main() {
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j <= 301; j++) {
      memo[i][j] = INF;
    }
  }
  cin >> n;
  cin >> c;
  int v;
  cin >> v;
  int s[v], t[v], y[v], m[v];
  memset(ygraph, 0, sizeof(ygraph));
  memset(mgraph, 0, sizeof(mgraph));
  for (int i = 0; i < v; i++) cin >> s[i];
  for (int i = 0; i < v; i++) cin >> t[i];
  for (int i = 0; i < v; i++) cin >> y[i];
  for (int i = 0; i < v; i++) cin >> m[i];

  for (int i = 0; i < v; i++) {
    ygraph[s[i]-1][t[i]-1] = y[i];
    mgraph[s[i]-1][t[i]-1] = m[i];
  }

  ans = INF;
  if (rec(0, c, 0) != INF) {
    cout << ans << endl;
  }else {
    cout << -1 << endl;
  }
}
0