結果
問題 | No.614 壊れたキャンパス |
ユーザー | te-sh |
提出日時 | 2017-12-14 10:14:06 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,373 bytes |
コンパイル時間 | 1,145 ms |
コンパイル使用メモリ | 128,724 KB |
実行使用メモリ | 98,048 KB |
最終ジャッジ日時 | 2024-06-12 23:03:43 |
合計ジャッジ時間 | 11,074 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | AC | 782 ms
85,760 KB |
testcase_09 | AC | 786 ms
82,048 KB |
testcase_10 | AC | 715 ms
90,752 KB |
testcase_11 | AC | 795 ms
79,104 KB |
testcase_12 | AC | 821 ms
79,104 KB |
testcase_13 | AC | 817 ms
79,104 KB |
testcase_14 | AC | 793 ms
86,528 KB |
testcase_15 | AC | 680 ms
88,576 KB |
testcase_16 | AC | 751 ms
84,352 KB |
testcase_17 | AC | 503 ms
98,048 KB |
testcase_18 | AC | 644 ms
73,856 KB |
testcase_19 | AC | 615 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, 10L^^18); 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)); } } } } }