結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
iicafiaxus
|
| 提出日時 | 2016-09-01 23:58:55 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,589 bytes |
| コンパイル時間 | 844 ms |
| コンパイル使用メモリ | 132,096 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 04:06:59 |
| 合計ジャッジ時間 | 2,108 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 WA * 24 |
ソースコード
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;
}
iicafiaxus