結果
問題 | No.196 典型DP (1) |
ユーザー | mkawa2 |
提出日時 | 2023-01-12 11:47:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 1,875 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 88,100 KB |
最終ジャッジ日時 | 2024-06-02 09:23:13 |
合計ジャッジ時間 | 5,038 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,480 KB |
testcase_01 | AC | 42 ms
52,736 KB |
testcase_02 | AC | 40 ms
52,352 KB |
testcase_03 | AC | 39 ms
52,608 KB |
testcase_04 | AC | 39 ms
52,352 KB |
testcase_05 | AC | 40 ms
52,480 KB |
testcase_06 | AC | 40 ms
52,608 KB |
testcase_07 | AC | 40 ms
52,480 KB |
testcase_08 | AC | 40 ms
52,736 KB |
testcase_09 | AC | 40 ms
52,480 KB |
testcase_10 | AC | 43 ms
53,120 KB |
testcase_11 | AC | 40 ms
52,352 KB |
testcase_12 | AC | 46 ms
59,136 KB |
testcase_13 | AC | 50 ms
60,800 KB |
testcase_14 | AC | 49 ms
60,672 KB |
testcase_15 | AC | 55 ms
61,952 KB |
testcase_16 | AC | 68 ms
67,200 KB |
testcase_17 | AC | 85 ms
74,624 KB |
testcase_18 | AC | 103 ms
77,056 KB |
testcase_19 | AC | 105 ms
77,184 KB |
testcase_20 | AC | 103 ms
77,184 KB |
testcase_21 | AC | 107 ms
77,056 KB |
testcase_22 | AC | 103 ms
77,056 KB |
testcase_23 | AC | 114 ms
77,496 KB |
testcase_24 | AC | 107 ms
77,100 KB |
testcase_25 | AC | 117 ms
80,676 KB |
testcase_26 | AC | 88 ms
77,312 KB |
testcase_27 | AC | 100 ms
77,824 KB |
testcase_28 | AC | 109 ms
78,208 KB |
testcase_29 | AC | 125 ms
88,100 KB |
testcase_30 | AC | 134 ms
88,056 KB |
testcase_31 | AC | 79 ms
73,600 KB |
testcase_32 | AC | 131 ms
77,444 KB |
testcase_33 | AC | 141 ms
77,192 KB |
testcase_34 | AC | 165 ms
77,068 KB |
testcase_35 | AC | 160 ms
77,060 KB |
testcase_36 | AC | 81 ms
74,496 KB |
testcase_37 | AC | 107 ms
77,376 KB |
testcase_38 | AC | 151 ms
77,468 KB |
testcase_39 | AC | 149 ms
77,064 KB |
testcase_40 | AC | 156 ms
76,928 KB |
testcase_41 | AC | 39 ms
52,352 KB |
testcase_42 | AC | 39 ms
52,608 KB |
testcase_43 | AC | 39 ms
52,736 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%md cur[s+t] %= md 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])