結果
問題 | No.614 壊れたキャンパス |
ユーザー | te-sh |
提出日時 | 2017-12-14 10:10:36 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,364 bytes |
コンパイル時間 | 1,081 ms |
コンパイル使用メモリ | 127,488 KB |
実行使用メモリ | 98,176 KB |
最終ジャッジ日時 | 2024-06-12 23:03:27 |
合計ジャッジ時間 | 10,830 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | AC | 706 ms
85,760 KB |
testcase_09 | AC | 698 ms
82,048 KB |
testcase_10 | AC | 597 ms
90,624 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 725 ms
79,232 KB |
testcase_14 | AC | 758 ms
86,528 KB |
testcase_15 | AC | 547 ms
88,704 KB |
testcase_16 | AC | 635 ms
84,480 KB |
testcase_17 | WA | - |
testcase_18 | AC | 552 ms
73,856 KB |
testcase_19 | AC | 627 ms
75,776 KB |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.math; // math functions alias graph = Graph!(long, int); alias edge = graph.Edge; void main() { auto rd = readln.split.to!(int[]), n = rd[0], m = rd[1], k = rd[2], s = rd[3], t = rd[4]; struct Rouka { int a, b, c; } auto roukas = new Rouka[](m); foreach (i; 0..m) { auto rd2 = readln.splitter; auto a = rd2.front.to!int-1; rd2.popFront(); auto b = rd2.front.to!int; rd2.popFront(); auto c = rd2.front.to!int; roukas[i] = Rouka(a, b, c); } auto r = new int[][](n); foreach (rouka; roukas) { r[rouka.a] ~= rouka.b; r[rouka.a+1] ~= rouka.c; } foreach (ri; r) ri.sort(); auto h = new int[int][](n), cnt = 1; foreach (i, ri; r) foreach (rij; ri) h[i][rij] = cnt++; auto g = new edge[][](cnt+1); foreach (i, ri; r) if (ri.length >= 2) foreach (j; 0..ri.length-1) { auto u = h[i][ri[j]], v = h[i][ri[j+1]], w = ri[j+1]-ri[j]; g[u] ~= edge(u, v, w); g[v] ~= edge(v, u, w); } foreach (rouka; roukas) { auto u = h[rouka.a][rouka.b], v = h[rouka.a+1][rouka.c]; g[u] ~= edge(u, v, 0); } foreach (rij; r[0]) { auto v = h[0][rij]; g[0] ~= edge(0, v, (s-rij).abs); } foreach (rij; r[$-1]) { auto u = h[$-1][rij]; g[u] ~= edge(u, cnt, (t-rij).abs); } auto dist = graph.dijkstra(g, 0); writeln(dist[cnt] == graph.inf ? -1 : dist[cnt]); } template Graph(Wt, Node, Wt _inf = 10 ^^ 9, Node _sent = Node.max) { import std.container; const inf = _inf, sent = _sent; struct Edge { Node src, dst; Wt wt; } Wt[] dijkstra(Edge[][] g, Node s) { Wt[] dist; Node[] prev; dijkstra(g, s, dist, prev); return dist; } void dijkstra(Edge[][] g, Node s, out Wt[] dist, out Node[] prev) { auto n = g.length; dist = new Wt[](n); dist[] = inf; dist[s] = 0; prev = new Node[](n); prev[] = sent; auto q = heapify!("a.wt > b.wt")(Array!Edge(Edge(sent, s, 0))); while (!q.empty) { auto e = q.front; q.removeFront(); if (prev[e.dst] != sent) continue; prev[e.dst] = e.src; foreach (f; g[e.dst]) { auto w = e.wt + f.wt; if (dist[f.dst] > w) { dist[f.dst] = w; q.insert(Edge(f.src, f.dst, w)); } } } } }