結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-31 22:20:31 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,221 bytes |
| コンパイル時間 | 768 ms |
| コンパイル使用メモリ | 120,756 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 04:03:15 |
| 合計ジャッジ時間 | 2,057 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random;
import std.string, std.conv, std.stdio, std.typecons;
struct path {
int e;
int y;
int m;
}
void main()
{
auto n = readln.chomp.to!int;
auto c = readln.chomp.to!int;
auto v = readln.chomp.to!int;
auto si = readln.split.map!(to!int).map!("a - 1");
auto ti = readln.split.map!(to!int).map!("a - 1");
auto yi = readln.split.map!(to!int);
auto mi = readln.split.map!(to!int);
auto tij = new int[][](n);
auto yij = new int[][](n);
auto mij = new int[][](n);
foreach (i; 0..v) {
tij[si[i]] ~= ti[i];
yij[si[i]] ~= yi[i];
mij[si[i]] ~= mi[i];
}
auto min = int.max;
auto stack = SList!path();
stack.insertFront(path(0, 0, 0));
while (!stack.empty) {
auto p = stack.front;
stack.removeFront;
if (p.e == n - 1) {
if (p.m < min) min = p.m;
continue;
}
foreach (i, t; tij[p.e]) {
auto y = yij[p.e][i];
auto m = mij[p.e][i];
if (y == 0 || m == 0 || p.m + m > min || p.y + y > c)
continue;
stack.insertFront(path(t, p.y + y, p.m + m));
}
}
writeln(min == int.max ? -1 : min);
}