結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー | yosupot |
提出日時 | 2017-01-01 22:16:21 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 7 ms / 5,000 ms |
コード長 | 4,152 bytes |
コンパイル時間 | 1,026 ms |
コンパイル使用メモリ | 137,088 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-12 06:13:08 |
合計ジャッジ時間 | 1,809 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 5 ms
5,376 KB |
testcase_06 | AC | 4 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 7 ms
5,376 KB |
testcase_09 | AC | 7 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 6 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
testcase_23 | AC | 4 ms
5,376 KB |
testcase_24 | AC | 5 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 6 ms
5,376 KB |
ソースコード
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.2.0" +/ import std.stdio, std.datetime, std.range, std.algorithm, std.conv; import std.numeric; import std.typecons; // import dcomp.scanner; // import dcomp.graph.dijkstra; alias Edge = Tuple!(int, "to", int, "dist"); int main(string[] argv) { auto sc = new Scanner(); int n; sc.read(n); Edge[][] g = new Edge[][](n); int[] s = new int[n]; foreach (i; 0..n) { sc.read(s[i]); } int m; sc.read(m); foreach (i; 0..m) { int a, b, c; sc.read(a, b, c); g[a] ~= Edge(b, c); g[b] ~= Edge(a, c); } int[][] dist = new int[][](n); foreach (i; 0..n) { dist[i] = g.dijkstra!int(i, 10^^8).dist; } int ans = 10^^8; foreach (i; 1..n-1) { foreach (j; 1..n-1) { if (i == j) continue; auto di = 0; di += dist[0][i] + dist[i][j] + dist[j][n-1]; di += s[i] + s[j]; ans = min(ans, di); } } writeln(ans); return 0; } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeChar, isStaticArray, isArray; import std.algorithm : map; File f; this(File f = stdin) { this.f = f; } string[] buf; private bool succ() { while (!buf.length) { if (f.eof) return false; buf = f.readln.split; } return true; } private bool readSingle(T)(ref T x) { if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { //string or char[10] etc x = buf.front; buf.popFront; } else { static if (isStaticArray!T) { //static assert(buf.length == T.length); } x = buf.map!(to!E).array; buf.length = 0; } } else { x = buf.front.to!T; buf.popFront; } return true; } int read(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } } unittest { import std.path : buildPath; import std.file : tempDir; import std.algorithm : equal; import std.stdio : File; string fileName = buildPath(tempDir, "kyuridenanmaida.txt"); auto fout = File(fileName, "w"); fout.writeln("1 2 3"); fout.writeln("ab cde"); fout.writeln("1.0 1.0 2.0"); fout.close; Scanner sc = new Scanner(File(fileName, "r")); int a; int[2] b; char[2] c; string d; double e; double[] f; sc.read(a, b, c, d, e, f); assert(a == 1); assert(equal(b[], [2, 3])); assert(equal(c[], "ab")); assert(equal(d, "cde")); assert(e == 1.0); assert(equal(f, [1.0, 2.0])); } /* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/graph/dijkstra.d */ // module dcomp.graph.djikstra; struct Dijkstra(T) { T[] dist; } Dijkstra!D dijkstra(D, T)(T g, int s, D inf = D.max) { import std.typecons : Tuple; import std.container.array; import std.container.binaryheap; import std.container.util : make; size_t V = g.length; Dijkstra!D dijk; dijk.dist.length = V; dijk.dist[] = inf; alias P = Tuple!(int, "to", D, "dist"); auto q = heapify!"a.dist>b.dist"(make!(Array!P)([P(D(0), s)])); dijk.dist[s] = D(0); while (!q.empty) { P p = q.front; q.popFront(); if (dijk.dist[p[1]] < p[0]) continue; foreach (e; g[p[1]]) { if (p[0]+e.dist < dijk.dist[e.to]) { dijk.dist[e.to] = p[0] + e.dist; q.insert(P(dijk.dist[e.to], e.to)); } } } return dijk; }