結果

問題 No.506 限られたジャパリまん
ユーザー qibqib
提出日時 2022-12-24 17:04:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 879 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 79,120 KB
最終ジャッジ日時 2023-09-10 12:58:41
合計ジャッジ時間 6,198 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,364 KB
testcase_01 AC 71 ms
71,508 KB
testcase_02 AC 82 ms
76,348 KB
testcase_03 AC 72 ms
71,340 KB
testcase_04 AC 377 ms
79,120 KB
testcase_05 AC 356 ms
78,676 KB
testcase_06 AC 73 ms
71,352 KB
testcase_07 AC 94 ms
76,812 KB
testcase_08 AC 306 ms
77,776 KB
testcase_09 AC 211 ms
77,488 KB
testcase_10 AC 108 ms
77,716 KB
testcase_11 AC 361 ms
77,996 KB
testcase_12 AC 250 ms
77,872 KB
testcase_13 AC 71 ms
75,164 KB
testcase_14 AC 92 ms
76,744 KB
testcase_15 AC 80 ms
76,388 KB
testcase_16 AC 262 ms
78,036 KB
testcase_17 AC 138 ms
78,036 KB
testcase_18 AC 206 ms
77,744 KB
testcase_19 AC 235 ms
77,616 KB
testcase_20 AC 271 ms
78,552 KB
testcase_21 AC 249 ms
78,512 KB
testcase_22 AC 394 ms
78,660 KB
testcase_23 AC 201 ms
78,144 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
for i in range(k):
  if (s >> i) & 1 != 0:
    print(friends[i])
0