結果

問題 No.1 道のショートカット
ユーザー mudbdbmudbdb
提出日時 2015-06-06 23:47:12
言語 C90
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,442 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 23,168 KB
実行使用メモリ 8,224 KB
最終ジャッジ日時 2024-07-08 04:05:14
合計ジャッジ時間 7,366 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
struct mati {
  int no; int Y; int M;
};
struct keiro {
  int S; int T; int Y; int M;
};
int main()
{
  int N, C, V, i;
  struct keiro *keiro;
  scanf("%d", &N);
  scanf("%d", &C);
  scanf("%d", &V);
  keiro = (struct keiro*)malloc(sizeof(struct keiro)*V);
  for (i=0; i<V; i++) scanf("%d", &(keiro[i].S));
  for (i=0; i<V; i++) scanf("%d", &(keiro[i].T));
  for (i=0; i<V; i++) scanf("%d", &(keiro[i].Y));
  for (i=0; i<V; i++) scanf("%d", &(keiro[i].M));

  int mati_top = -1;
  struct mati *mati = (struct mati*)malloc(sizeof(struct mati)*N);
  int work_top = -1;
  struct keiro *work = (struct keiro*)malloc(sizeof(struct keiro)*V);
  int check;
  int check_jikan;

  int jikan = 0;
  for (i=0; i<V; i++) jikan += keiro[i].M;
  jikan++;
  check_jikan = jikan;

  mati_top++;
  mati[mati_top].no = 1;
  mati[mati_top].Y = C;
  mati[mati_top].M = 0;

  check = 0;
  for (i=0; i<V; i++) {
    if (mati[mati_top].no == keiro[i].S) {
      work_top++;
      work[work_top] = keiro[i];
      check++;
    }
  }
  if (check == 0) {
    printf("%d\n", -1);
    return 0;
  }

  while (1) {
    mati_top++;
    mati[mati_top].no = work[work_top].T;
    mati[mati_top].Y = mati[mati_top-1].Y - work[work_top].Y;
    mati[mati_top].M = mati[mati_top-1].M + work[work_top].M;

    if (mati[mati_top].no == N) {
      if (mati[mati_top].Y >= 0) {
        if (mati[mati_top].M < jikan) {
          jikan = mati[mati_top].M;
        }
      }

      mati_top--;
      while (1) {
        work_top--;
        if (work_top == -1) {
          break;
        } else {
          if (work[work_top].S < work[work_top+1].S) {
            mati_top--;
            continue;
          } else {
            break;
          }
        }
      }
    } else {
      check = 0;
      for (i=0; i<V; i++) {
        if (mati[mati_top].no == keiro[i].S) {
          work_top++;
          work[work_top] = keiro[i];
          check++;
        }
      }
      if (check == 0) {
        while (1) {
          work_top--;
          if (work_top == -1) {
            break;
          } else {
            if (work[work_top].S < work[work_top+1].S) {
              mati_top--;
              continue;
            } else {
              break;
            }
          }
        }
      }
    }
    if (work_top == -1) break;
  }
  if (jikan == check_jikan) {
    printf("%d\n", -1);
  } else {
    printf("%d\n", jikan);
  }
  return 0;
}
0