結果
問題 | No.1 道のショートカット |
ユーザー | mudbdb |
提出日時 | 2015-06-08 00:17:13 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 3,165 bytes |
コンパイル時間 | 335 ms |
コンパイル使用メモリ | 23,296 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:14:51 |
合計ジャッジ時間 | 1,530 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
5,248 KB |
testcase_01 | AC | 0 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 | 1 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 | 1 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 0 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 2 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 | 2 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 1 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 | 2 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 | 1 ms
5,376 KB |
コンパイルメッセージ
main.c: In function ‘main’: main.c:20:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d", &N); | ^~~~~~~~~~~~~~~ main.c:21:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf("%d", &C); | ^~~~~~~~~~~~~~~ main.c:22:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf("%d", &V); | ^~~~~~~~~~~~~~~ main.c:24:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | for (i=0; i<V; i++) scanf("%d", &(keiro[i].S)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ main.c:25:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | for (i=0; i<V; i++) scanf("%d", &(keiro[i].T)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ main.c:26:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | for (i=0; i<V; i++) scanf("%d", &(keiro[i].Y)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ main.c:27:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | for (i=0; i<V; i++) scanf("%d", &(keiro[i].M)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <stdlib.h> struct keiro { int S; int T; int Y; int M; }; int cmp(const void* a, const void* b) { struct keiro *c = (struct keiro*)a; struct keiro *d = (struct keiro*)b; if (c->S == d->S) { return (c->T - d->T); } else { return (c->S - d->S); } } 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)); qsort(keiro, V, sizeof(struct keiro), cmp); struct keiro_start { int pos; int renge; struct keiro *keiro; }; struct keiro_start *keiro_start = (struct keiro_start*)malloc(sizeof(struct keiro_start )*N); for (i=0; i<N; i++) keiro_start[i].renge = 0; for (i=0; i<V; i++) keiro_start[keiro[i].S - 1].renge ++; keiro_start[0].pos = 0; for (i=1; i<N; i++) keiro_start[i].pos = keiro_start[i-1].pos + keiro_start[i-1].renge; for (i=0; i<N; i++) if (keiro_start[i].renge == 0) { keiro_start[i].keiro = 0; } else { keiro_start[i].keiro = &(keiro[keiro_start[i].pos]); } int check_jikan; int jikan = 0; for (i=0; i<V; i++) jikan += keiro[i].M; jikan++; check_jikan = jikan; struct mati { int no; int Y; int M; int keiro_i; int keiro_n; struct keiro *keiro; }; struct mati *mati = (struct mati*)malloc(sizeof(struct mati)*N); struct mati *mati_p = mati; mati_p->no = 1; mati_p->Y = C; mati_p->M = 0; mati_p->keiro_i = 0; mati_p->keiro_n = keiro_start[mati_p->no - 1].renge; mati_p->keiro = keiro_start[mati_p->no - 1].keiro; struct mati *mati_from = 0; while (mati_p->keiro != 0 && mati_p->Y >= 0 && mati_p->M < jikan) { mati_from = mati_p; mati_p++; mati_p->no = mati_from->keiro->T; mati_p->Y = mati_from->Y - mati_from->keiro->Y; mati_p->M = mati_from->M + mati_from->keiro->M; mati_p->keiro_i = 0; mati_p->keiro_n = keiro_start[mati_p->no - 1].renge; mati_p->keiro = keiro_start[mati_p->no - 1].keiro; } while (1) { if (mati_p->no == N) { if (mati_p->Y >= 0) { if (mati_p->M < jikan) { jikan = mati_p->M; } } } while (1) { if (mati_p == mati) { goto END; } else { mati_p--; mati_p->keiro_i++; if (mati_p->keiro_i < mati_p->keiro_n) { mati_p->keiro++; break; } else { continue; } } } while (mati_p->keiro != 0 && mati_p->Y >= 0 && mati_p->M < jikan) { mati_from = mati_p; mati_p++; mati_p->no = mati_from->keiro->T; mati_p->Y = mati_from->Y - mati_from->keiro->Y; mati_p->M = mati_from->M + mati_from->keiro->M; mati_p->keiro_i = 0; mati_p->keiro_n = keiro_start[mati_p->no - 1].renge; mati_p->keiro = keiro_start[mati_p->no - 1].keiro; } } END: if (jikan == check_jikan) { printf("%d\n", -1); } else { printf("%d\n", jikan); } return 0; }