結果
問題 | No.1690 Power Grid |
ユーザー |
|
提出日時 | 2021-09-24 22:22:19 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 877 ms / 3,000 ms |
コード長 | 1,618 bytes |
コンパイル時間 | 884 ms |
コンパイル使用メモリ | 121,516 KB |
実行使用メモリ | 84,056 KB |
最終ジャッジ日時 | 2024-06-22 12:36:35 |
合計ジャッジ時間 | 13,150 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop;immutable long MOD = 998244353;immutable long inf = 1L << 59;void main() {auto s = readln.split.map!(to!int);auto N = s[0];auto M = s[1];auto K = s[2];auto A = readln.split.map!(to!long).array;auto G = new long[][](N, N);foreach (i; 0..N) G[i][] = inf;foreach (i; 0..M) {s = readln.split.map!(to!int);auto u = s[0] - 1;auto v = s[1] - 1;auto z = s[2];G[u][v] = G[v][u] = z.to!long;}auto dist = new long[][](N, N);foreach (i; 0..N) foreach (j; 0..N) dist[i][j] = G[i][j];foreach (i; 0..N) foreach (j; 0..N) foreach (k; 0..N) if (dist[j][i] != inf && dist[i][k] != inf) {dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);}auto dist2 = new long[][](N, 1<<N);foreach (i; 0..N) dist2[i][] = inf;foreach (i; 0..N) foreach (mask; 0..1<<N) {foreach (j; 0..N) if (mask & (1 << j)) dist2[i][mask] = min(dist2[i][mask], dist[i][j]);}auto dp = new long[][](K+1, 1<<N);foreach (i; 0..K+1) dp[i][] = inf;dp[0][0] = 0;foreach (i; 0..K) foreach (mask; 0..1<<N) foreach (j; 0..N) if (!(mask & (1 << j))) {if (i == 0) {dp[i+1][mask|(1<<j)] = min(dp[i+1][mask|(1<<j)], dp[i][mask] + A[j]);} else {dp[i+1][mask|(1<<j)] = min(dp[i+1][mask|(1<<j)], dp[i][mask] + A[j] + dist2[j][mask]);}}dp[K].reduce!min.writeln;}