結果

問題 No.506 限られたジャパリまん
ユーザー qibqib
提出日時 2022-12-24 17:06:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 413 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 86,412 KB
実行使用メモリ 78,844 KB
最終ジャッジ日時 2023-09-10 12:58:44
合計ジャッジ時間 6,374 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
70,680 KB
testcase_01 AC 73 ms
70,776 KB
testcase_02 AC 81 ms
75,656 KB
testcase_03 AC 71 ms
70,932 KB
testcase_04 AC 388 ms
78,844 KB
testcase_05 AC 361 ms
78,264 KB
testcase_06 AC 71 ms
70,892 KB
testcase_07 AC 94 ms
76,188 KB
testcase_08 AC 316 ms
77,252 KB
testcase_09 AC 215 ms
77,212 KB
testcase_10 AC 109 ms
77,312 KB
testcase_11 AC 374 ms
77,988 KB
testcase_12 AC 261 ms
77,268 KB
testcase_13 AC 77 ms
74,928 KB
testcase_14 AC 95 ms
76,364 KB
testcase_15 AC 80 ms
75,732 KB
testcase_16 AC 267 ms
77,336 KB
testcase_17 AC 145 ms
77,388 KB
testcase_18 AC 215 ms
77,500 KB
testcase_19 AC 242 ms
77,348 KB
testcase_20 AC 286 ms
78,048 KB
testcase_21 AC 263 ms
78,456 KB
testcase_22 AC 413 ms
78,588 KB
testcase_23 AC 206 ms
77,592 KB
testcase_24 AC 224 ms
76,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

h, w, k, p = map(int, input().split())
points = []
friends = []
for _ in range(k):
  x, y, name = input().split()
  points.append((int(x), int(y)))
  friends.append(name)

dp = [[-1 for _ in range(w + 1)] for _ in range(h + 1)]
s = None
for mask in range(1 << k):
  ndp = [[0 for _ in range(w + 1)] for _ in range(h + 1)]
  ndp[0][0] = 1
  banned = {}
  for i in range(k):
    if (mask >> i) & 1 != 0:
      continue
    x, y = points[i]
    banned[(x, y)] = True

  if len(banned) != k - p:
    continue

  for x in range(h + 1):
    for y in range(w + 1):
      if banned.get((x, y), False):
        continue
      if x > 0:
        ndp[x][y] += ndp[x - 1][y]
      if y > 0:
        ndp[x][y] += ndp[x][y - 1]

  if dp[-1][-1] < ndp[-1][-1]:
    dp = ndp
    s = mask

print(dp[-1][-1] % MOD)
if dp[-1][-1] != 0:
  for i in range(k):
    if (s >> i) & 1 != 0:
      print(friends[i])
0