結果

問題 No.1 道のショートカット
ユーザー iicafiaxusiicafiaxus
提出日時 2016-09-02 00:23:11
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,589 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 119,244 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:52:20
合計ジャッジ時間 2,780 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 3 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 3 ms
4,368 KB
testcase_11 AC 3 ms
4,372 KB
testcase_12 AC 4 ms
4,372 KB
testcase_13 AC 4 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 1 ms
4,368 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 1 ms
4,368 KB
testcase_18 AC 2 ms
4,368 KB
testcase_19 AC 1 ms
4,368 KB
testcase_20 AC 1 ms
4,368 KB
testcase_21 AC 1 ms
4,372 KB
testcase_22 AC 1 ms
4,372 KB
testcase_23 AC 4 ms
4,368 KB
testcase_24 AC 3 ms
4,368 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
testcase_27 AC 4 ms
4,372 KB
testcase_28 AC 1 ms
4,368 KB
testcase_29 AC 4 ms
4,368 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 2 ms
4,372 KB
testcase_32 AC 2 ms
4,368 KB
testcase_33 AC 3 ms
4,368 KB
testcase_34 AC 3 ms
4,368 KB
testcase_35 AC 3 ms
4,368 KB
testcase_36 AC 2 ms
4,368 KB
testcase_37 AC 2 ms
4,368 KB
testcase_38 AC 2 ms
4,368 KB
testcase_39 AC 1 ms
4,368 KB
testcase_40 AC 2 ms
4,372 KB
testcase_41 AC 2 ms
4,368 KB
testcase_42 AC 1 ms
4,368 KB
testcase_43 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

class Edge{
	Node from;
	Node to;
	int cost;
	int time;
	this(Node from, Node to, int cost, int time){
		this.from = from;
		this.to = to;
		this.cost = cost;
		this.time = time;
		to.inedges ~= this;
		}
	}

class Node{
	Edge[] inedges;
	int[int] xs; // cost -> time
	this(){
		}
	}	

void main(){
	int n = readln.chomp.to!int;
	int c = readln.chomp.to!int;
	int v = readln.chomp.to!int;
	int[] ss = readln.chomp.split.map!(to!int).map!(x => x - 1).array;
	int[] ts = readln.chomp.split.map!(to!int).map!(x => x - 1).array;
	int[] ys = readln.chomp.split.map!(to!int).array;
	int[] ms = readln.chomp.split.map!(to!int).array;
	
	Node[] nodes;
	nodes ~= new Node;
	nodes[0].xs[0] = 0;
	foreach(i; 0 .. n) nodes ~= new Node;
	
	Edge[] edges;
	for(int i = 0; i < v; i ++){
		edges ~= new Edge(nodes[ss[i]], nodes[ts[i]], ys[i], ms[i]);
		}
	
	foreach(no; nodes){
		foreach(ed; no.inedges){
			foreach(cq; ed.from.xs.keys){
				if(cq + ed.cost <= c){
					if(!(cq + ed.cost in no.xs) || no.xs[cq + ed.cost] > ed.from.xs[cq] + ed.time){
						no.xs[cq + ed.cost] = ed.from.xs[cq] + ed.time;
						}
					}
				}
			}
		int thr = int.max;
		int[] ks = no.xs.keys;
		ks.sort!("a < b")();
		foreach(k; ks){
			if(no.xs[k] >= thr) no.xs.remove(k);
			else thr = no.xs[k];
			}
		}
	
	int ans = -1;
	if(nodes[n - 1].xs.keys.length){
		int min = int.max;
		foreach(t; nodes[n - 1].xs){
			if(t < min) min = t;
			}
		ans = min;
		}
	
	ans.writeln;
	
	}
0