結果

問題 No.1 道のショートカット
ユーザー matsu7874
提出日時 2015-12-07 22:21:04
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,184 bytes
コンパイル時間 1,300 ms
コンパイル使用メモリ 161,884 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:18:36
合計ジャッジ時間 2,304 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |   scanf("%d", &N);
      |   ~~~~~^~~~~~~~~~
main.cpp:17:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |   scanf("%d", &C);
      |   ~~~~~^~~~~~~~~~
main.cpp:18:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   scanf("%d", &V);
      |   ~~~~~^~~~~~~~~~
main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     scanf("%d", &S[i]);
      |     ~~~~~^~~~~~~~~~~~~
main.cpp:25:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |     scanf("%d", &T[i]);
      |     ~~~~~^~~~~~~~~~~~~
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |     scanf("%d", &Y[i]);
      |     ~~~~~^~~~~~~~~~~~~
main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |     scanf("%d", &M[i]);
      |     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define ALL(c) c.begin(), c.end()
#define REP(i, n) \
  for (int i = 0; i < (int)(n); ++i)
#define FOR(i, l, r) \
  for (int i = (int)(l); i < (int)(r); ++i)
#define EACH(it, o) \
  for (auto it = (o).begin(); it != (o).end(); ++it)

#define INF (1 << 26)
using namespace std;

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

  scanf("%d", &N);
  scanf("%d", &C);
  scanf("%d", &V);
  int S[V], T[V], Y[V], M[V];
  REP(i, V) {
    scanf("%d", &S[i]);
  }

  REP(i, V) {
    scanf("%d", &T[i]);
  }

  REP(i, V) {
    scanf("%d", &Y[i]);
  }

  REP(i, V) {
    scanf("%d", &M[i]);
  }

  int p[V];
  REP(i, V) {
    p[i] = i;
  }
  sort(p, p + V, [&](int a, int b) {
    return S[a] < S[b];
  });

  long dp[N + 1][C + 1];

  REP(i, N + 1) {
    REP(j, C + 1) {
      dp[i][j] = INF;
    }
  }
  dp[1][C] = 0;

  REP(i, V) {
    int ptr = p[i];

    REP(j, C+1) {
      if (Y[ptr] + j <= C) {
        dp[T[ptr]][j] = min(dp[T[ptr]][j], dp[S[ptr]][j + Y[ptr]] + M[ptr]);
      }
    }
  }

  long min_time = INF;

  REP(i, C+1) {
    min_time = min(min_time, dp[N][i]);
  }

  if (min_time == INF) {
    printf("-1\n");
  } else {
    printf("%ld\n", min_time);
  }
  return 0;
}
0