結果
問題 |
No.506 限られたジャパリまん
|
ユーザー |
![]() |
提出日時 | 2025-06-12 19:46:06 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,037 bytes |
コンパイル時間 | 162 ms |
コンパイル使用メモリ | 82,396 KB |
実行使用メモリ | 79,084 KB |
最終ジャッジ日時 | 2025-06-12 19:46:20 |
合計ジャッジ時間 | 13,927 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 12 TLE * 1 |
ソースコード
MOD = 10**9 + 7 def main(): import sys input = sys.stdin.read().split('\n') idx = 0 H, W, K, P = map(int, input[idx].split()) idx += 1 points = [] blocked = {} for i in range(K): if idx >= len(input): x, y, name = 0, 0, '' else: line = input[idx].strip() while line == '': idx += 1 line = input[idx].strip() x, y, name = line.split() x = int(x) y = int(y) points.append((x, y, name)) blocked[(x, y)] = i idx += 1 max_mask = 1 << K best = -1 best_mask = 0 is_blocked = [[False] * (W+1) for _ in range(H+1)] for (x, y) in blocked: is_blocked[x][y] = True for mask in range(max_mask): if bin(mask).count('1') > P: continue dp = [[0] * (W + 1) for _ in range(H + 1)] dp[0][0] = 1 for s in range(0, H + W + 1): for x in range(0, H + 1): y = s - x if y < 0 or y > W: continue if x == 0 and y == 0: continue total = 0 if x > 0: total += dp[x-1][y] if y > 0: total += dp[x][y-1] total %= MOD if (x, y) in blocked: i = blocked[(x, y)] if (mask & (1 << i)): dp[x][y] = total else: dp[x][y] = 0 else: dp[x][y] = total current = dp[H][W] % MOD if current > best: best = current best_mask = mask if best == 0: print(0) else: print(best % MOD) selected = [] for i in range(K): if (best_mask & (1 << i)): selected.append(points[i][2]) for name in selected: print(name) if __name__ == '__main__': main()