結果
問題 | No.2387 Yokan Factory |
ユーザー | InTheBloom |
提出日時 | 2023-07-21 22:10:27 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 641 ms / 5,000 ms |
コード長 | 2,200 bytes |
コンパイル時間 | 4,566 ms |
コンパイル使用メモリ | 177,156 KB |
実行使用メモリ | 25,768 KB |
最終ジャッジ日時 | 2023-10-21 22:10:37 |
合計ジャッジ時間 | 10,598 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,348 KB |
testcase_01 | AC | 1 ms
4,372 KB |
testcase_02 | AC | 1 ms
4,372 KB |
testcase_03 | AC | 1 ms
4,372 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 | 2 ms
4,372 KB |
testcase_08 | AC | 1 ms
4,372 KB |
testcase_09 | AC | 1 ms
4,372 KB |
testcase_10 | AC | 1 ms
4,372 KB |
testcase_11 | AC | 1 ms
4,372 KB |
testcase_12 | AC | 1 ms
4,372 KB |
testcase_13 | AC | 1 ms
4,372 KB |
testcase_14 | AC | 1 ms
4,372 KB |
testcase_15 | AC | 426 ms
15,308 KB |
testcase_16 | AC | 250 ms
25,768 KB |
testcase_17 | AC | 571 ms
25,564 KB |
testcase_18 | AC | 534 ms
18,400 KB |
testcase_19 | AC | 400 ms
15,308 KB |
testcase_20 | AC | 322 ms
14,784 KB |
testcase_21 | AC | 641 ms
18,664 KB |
testcase_22 | AC | 302 ms
15,048 KB |
testcase_23 | AC | 447 ms
15,120 KB |
testcase_24 | AC | 189 ms
15,080 KB |
testcase_25 | AC | 59 ms
12,144 KB |
testcase_26 | AC | 114 ms
14,728 KB |
testcase_27 | AC | 133 ms
17,276 KB |
testcase_28 | AC | 5 ms
5,000 KB |
testcase_29 | AC | 6 ms
5,264 KB |
testcase_30 | AC | 6 ms
5,264 KB |
testcase_31 | AC | 4 ms
5,000 KB |
testcase_32 | AC | 3 ms
4,372 KB |
testcase_33 | AC | 3 ms
4,372 KB |
testcase_34 | AC | 6 ms
5,264 KB |
testcase_35 | AC | 3 ms
4,372 KB |
testcase_36 | AC | 3 ms
4,372 KB |
testcase_37 | AC | 1 ms
4,372 KB |
ソースコード
import std; struct node { int vertex; int weight; int width; } void main () { int N, M; long X; readln.read(N, M, X); node[][] graph = new node[][](N, 0); foreach (i; 0..M) { int u, v, a, b; readln.read(u, v, a, b); u--, v--; graph[u] ~= node(v, a, b); graph[v] ~= node(u, a, b); } solve(N, M, X, graph); } void solve (int N, int M, long X, node[][] graph) { // 羊羹の大きさで二分探索する // 判定問題はダイクストラ法を解くことと等価であり、ヒープキューを使ってO(|E|log|V|)らしい(しらん) // まず、最小羊羹で到達できるかをチェック if (!dijkstra(graph, X, 1)) { writeln(-1); return; } // 二分探索 条件: f(ok) = true かつ f(ng) = false int ok = 1, ng = 100_000_000_1; while (1 < abs(ok-ng)) { int mid = (ok+ng) / 2; if (dijkstra(graph, X, mid)) { ok = mid; } else { ng = mid; } } writeln(ok); } bool dijkstra (node[][] graph, long X, int wid) { struct toNode { int vertex; long totalCost; } long[] comfirmedCost = new long[](graph.length); comfirmedCost[] = long.max; BinaryHeap!(Array!toNode, "a.totalCost > b.totalCost") PQ; PQ.insert(toNode(0, 0)); comfirmedCost[0] = 0; while (!PQ.empty) { auto shortest = PQ.front; PQ.removeFront; if (comfirmedCost[shortest.vertex] < shortest.totalCost) { continue; } foreach (to; graph[shortest.vertex]) { if (to.width < wid) { continue; } if (to.weight + shortest.totalCost < comfirmedCost[to.vertex]) { comfirmedCost[to.vertex] = to.weight + shortest.totalCost; PQ.insert(toNode(to.vertex, comfirmedCost[to.vertex])); } } } if (comfirmedCost[$-1] == long.max || X < comfirmedCost[$-1]) { return false; } return true; } void read(T...)(string S, ref T args) { auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }