結果
問題 | No.196 典型DP (1) |
ユーザー | mkawa2 |
提出日時 | 2023-01-12 11:46:16 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,845 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 115,176 KB |
最終ジャッジ日時 | 2024-06-02 09:22:08 |
合計ジャッジ時間 | 6,288 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,992 KB |
testcase_01 | AC | 29 ms
52,096 KB |
testcase_02 | AC | 30 ms
52,608 KB |
testcase_03 | AC | 31 ms
52,864 KB |
testcase_04 | AC | 30 ms
52,352 KB |
testcase_05 | AC | 31 ms
52,480 KB |
testcase_06 | AC | 30 ms
52,480 KB |
testcase_07 | AC | 30 ms
52,352 KB |
testcase_08 | AC | 31 ms
52,608 KB |
testcase_09 | AC | 30 ms
52,224 KB |
testcase_10 | AC | 30 ms
52,736 KB |
testcase_11 | AC | 31 ms
52,608 KB |
testcase_12 | WA | - |
testcase_13 | AC | 37 ms
60,928 KB |
testcase_14 | AC | 37 ms
60,416 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 70 ms
77,184 KB |
testcase_27 | AC | 76 ms
77,696 KB |
testcase_28 | AC | 75 ms
78,464 KB |
testcase_29 | AC | 88 ms
88,448 KB |
testcase_30 | AC | 95 ms
88,152 KB |
testcase_31 | AC | 59 ms
73,344 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 349 ms
93,320 KB |
testcase_36 | AC | 58 ms
74,132 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 369 ms
93,780 KB |
testcase_41 | AC | 33 ms
52,992 KB |
testcase_42 | AC | 31 ms
52,736 KB |
testcase_43 | AC | 31 ms
52,352 KB |
ソースコード
import sys # sys.setrecursionlimit(1000005) 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, k = LI() to = [[] for _ in range(n)] for _ in range(n-1): u, v = LI() to[u].append(v) to[v].append(u) parent, depth, vis = [-1]*n, [0]*n, [0]*n def dfs(root): uu = [] vis[root] = 1 stack = [root] while stack: iu = stack.pop() i, u = divmod(iu, n) if i == 0: uu.append(u) # care to's format while i < len(to[u]) and vis[to[u][i]]: i += 1 if i < len(to[u]): stack.append((i+1)*n+u) # care to's format v = to[u][i] vis[v] = 1 stack.append(v) parent[v] = u depth[v] = depth[u]+1 return uu uu = dfs(0) size = [1]*n for u in uu[:0:-1]: p = parent[u] size[p] += size[u] def merge(p, u): m = min(k+1, len(dp[p])+len(dp[u])-1) cur = [0]*m for s, c in enumerate(dp[p]): for t, d in enumerate(dp[u]): if s+t >= m: break cur[s+t] += c*d dp[p] = cur dp = [[1] for _ in range(n)] for u in uu[::-1]: if len(dp[u]) <= k: dp[u].append(1) p = parent[u] merge(p, u) print(dp[0][k])