結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
mudbdb
|
| 提出日時 | 2015-06-07 00:01:00 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,771 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 23,296 KB |
| 実行使用メモリ | 8,348 KB |
| 最終ジャッジ日時 | 2024-07-08 04:05:22 |
| 合計ジャッジ時間 | 6,859 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 WA * 1 TLE * 1 -- * 32 |
コンパイルメッセージ
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));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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].Y < 0) {
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 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;
}
mudbdb