結果

問題 No.1 道のショートカット
ユーザー mudbdbmudbdb
提出日時 2015-06-09 04:47:19
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,429 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 22,272 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:14:52
合計ジャッジ時間 1,364 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 0 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 0 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 0 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:30:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |   scanf("%d", &N);
      |   ^~~~~~~~~~~~~~~
main.c:31:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |   scanf("%d", &C);
      |   ^~~~~~~~~~~~~~~
main.c:32:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |   scanf("%d", &V);
      |   ^~~~~~~~~~~~~~~
main.c:34:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |   for (i=0; i<V; i++) scanf("%d", &(Route[i].S));
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:35:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |   for (i=0; i<V; i++) scanf("%d", &(Route[i].T));
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:36:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   for (i=0; i<V; i++) scanf("%d", &(Route[i].Y));
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:37:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   for (i=0; i<V; i++) scanf("%d", &(Route[i].M));
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
int N, C, V;
int M_min = 0;
struct route { int S; int T; int Y; int M; };
struct route *Route;
struct town { int route_n; int *route; };
struct town *Town;
void go(int no, int Y, int M)
{
  if (no == N) {
    M_min = M;
  } else {
    int i;
    struct town *townp = &(Town[no - 1]);
    for (i=0; i<townp->route_n; i++) {
      struct route *routep = &(Route[townp->route[i]]);
      int YY = Y + routep->Y;
      int MM = M + routep->M;
      if (YY <= C && MM < M_min) {
        go(routep->T, YY, MM);
      }
    }
  }
  return;
}
int main()
{
  int i;
  scanf("%d", &N);
  scanf("%d", &C);
  scanf("%d", &V);
  Route = (struct route*)malloc(sizeof(struct route)*V);
  for (i=0; i<V; i++) scanf("%d", &(Route[i].S));
  for (i=0; i<V; i++) scanf("%d", &(Route[i].T));
  for (i=0; i<V; i++) scanf("%d", &(Route[i].Y));
  for (i=0; i<V; i++) scanf("%d", &(Route[i].M));

  for (i=0; i<V; i++) M_min += Route[i].M;
  M_min++;
  int check = M_min;

  Town = (struct town*)malloc(sizeof(struct town)*N);
  struct town *townp = Town;
  for (i=0; i<N; i++) {
    townp->route = (int*)malloc(sizeof(int)*V);
    townp->route_n = 0;
    townp++;
  }
  for (i=0; i<V; i++) {
    townp = &(Town[Route[i].S - 1]);
    townp->route[townp->route_n] = i;
    townp->route_n++;
  }

  go(1, 0, 0);

  if (check == M_min) {
    printf("%d\n", -1);
  } else {
    printf("%d\n", M_min);
  }
  return 0;
}
0