結果
| 問題 |
No.506 限られたジャパリまん
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 23:34:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,403 bytes |
| コンパイル時間 | 319 ms |
| コンパイル使用メモリ | 82,272 KB |
| 実行使用メモリ | 76,972 KB |
| 最終ジャッジ日時 | 2025-04-15 23:35:52 |
| 合計ジャッジ時間 | 6,652 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 13 |
ソースコード
MOD = 10**9 + 7
H, W, K, P = map(int, input().split())
friends = []
friend_grid = [[-1 for _ in range(W+1)] for _ in range(H+1)]
for i in range(K):
x, y, name = input().split()
x = int(x)
y = int(y)
friends.append((x, y, name))
friend_grid[x][y] = i
max_count = -1
best_mask = 0
for mask in range(0, 1 << K):
cnt = bin(mask).count('1')
if cnt > P:
continue
dp = [[0] * (W + 1) for _ in range(H + 1)]
dp[0][0] = 1
for x in range(H + 1):
for y in range(W + 1):
if x == 0 and y == 0:
continue
blocked = False
friend_idx = friend_grid[x][y]
if friend_idx != -1:
if not (mask & (1 << friend_idx)):
blocked = True
if blocked:
dp[x][y] = 0
else:
total = 0
if x > 0:
total += dp[x-1][y]
if y > 0:
total += dp[x][y-1]
dp[x][y] = total % MOD
current_count = dp[H][W]
if current_count > max_count:
max_count = current_count
best_mask = mask
if max_count <= 0:
print(0)
else:
print(max_count % MOD)
selected_names = []
for i in range(K):
if best_mask & (1 << i):
selected_names.append(friends[i][2])
for name in selected_names:
print(name)
lam6er