結果
問題 | No.1690 Power Grid |
ユーザー | mkawa2 |
提出日時 | 2022-03-01 00:08:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,607 ms / 3,000 ms |
コード長 | 1,453 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 79,460 KB |
最終ジャッジ日時 | 2024-07-07 03:20:46 |
合計ジャッジ時間 | 25,610 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
52,688 KB |
testcase_01 | AC | 34 ms
53,796 KB |
testcase_02 | AC | 95 ms
76,508 KB |
testcase_03 | AC | 33 ms
52,400 KB |
testcase_04 | AC | 34 ms
53,076 KB |
testcase_05 | AC | 36 ms
53,956 KB |
testcase_06 | AC | 1,459 ms
78,580 KB |
testcase_07 | AC | 1,521 ms
78,684 KB |
testcase_08 | AC | 1,466 ms
78,720 KB |
testcase_09 | AC | 1,542 ms
78,784 KB |
testcase_10 | AC | 1,216 ms
78,516 KB |
testcase_11 | AC | 1,260 ms
79,112 KB |
testcase_12 | AC | 34 ms
52,692 KB |
testcase_13 | AC | 81 ms
76,472 KB |
testcase_14 | AC | 244 ms
76,812 KB |
testcase_15 | AC | 1,209 ms
78,696 KB |
testcase_16 | AC | 1,483 ms
79,212 KB |
testcase_17 | AC | 640 ms
77,984 KB |
testcase_18 | AC | 393 ms
77,232 KB |
testcase_19 | AC | 1,481 ms
78,932 KB |
testcase_20 | AC | 1,568 ms
78,852 KB |
testcase_21 | AC | 1,322 ms
78,728 KB |
testcase_22 | AC | 1,511 ms
79,192 KB |
testcase_23 | AC | 1,188 ms
78,692 KB |
testcase_24 | AC | 1,607 ms
79,372 KB |
testcase_25 | AC | 1,464 ms
79,460 KB |
testcase_26 | AC | 1,292 ms
79,280 KB |
testcase_27 | AC | 36 ms
53,948 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 n, m, k = LI() aa = LI() dist = [[inf]*n for _ in range(n)] for u in range(n): dist[u][u] = 0 for _ in range(m): u, v, z = LI() u, v = u-1, v-1 dist[u][v] = dist[v][u] = z for v in range(n): for u in range(n): for w in range(n): dist[u][w] = min(dist[u][w], dist[u][v]+dist[v][w]) def popcnt(a): return bin(a).count("1") dp = [inf]*(1 << n) ans = inf for s in range(1, 1 << n): pc = popcnt(s) if pc == 1: dp[s] = aa[s.bit_length()-1] if pc == k: ans = min(ans, dp[s]) for u in range(n): if s >> u & 1: continue ns = s | 1 << u cost = min(dist[u][v] for v in range(n) if s >> v & 1)+aa[u] dp[ns] = min(dp[ns], dp[s]+cost) print(ans)