結果
問題 | No.506 限られたジャパリまん |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:18:03 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,370 bytes |
コンパイル時間 | 321 ms |
コンパイル使用メモリ | 82,600 KB |
実行使用メモリ | 78,232 KB |
最終ジャッジ日時 | 2025-03-20 21:19:27 |
合計ジャッジ時間 | 13,346 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 13 |
ソースコード
H, W, K, P = map(int, input().split())friends = []grid_map = {}for i in range(K):x, y, name = input().split()x = int(x)y = int(y)friends.append((x, y, name))grid_map[(x, y)] = i # Maps coordinate to friend indexMOD = 10**9 + 7max_count = -1best_mask = 0for mask in range(0, 1 << K):selected = bin(mask).count('1')if selected > P:continuedp = [[0] * (W + 1) for _ in range(H + 1)]dp[0][0] = 1 # Starting pointfor x in range(H + 1):for y in range(W + 1):if x == 0 and y == 0:continueblocked = Falseif (x, y) in grid_map:idx = grid_map[(x, y)]if not (mask & (1 << idx)):blocked = Trueif blocked:dp[x][y] = 0else:total = 0if x > 0:total += dp[x-1][y]if y > 0:total += dp[x][y-1]dp[x][y] = total % MODcurrent_count = dp[H][W]if current_count > max_count:max_count = current_countbest_mask = maskif max_count <= 0:print(0)else:print(max_count % MOD)selected_names = [friends[i][2] for i in range(K) if (best_mask & (1 << i))]for name in selected_names:print(name)