結果

問題 No.506 限られたジャパリまん
ユーザー lloyzlloyz
提出日時 2023-04-08 11:05:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,922 ms / 2,000 ms
コード長 966 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 78,932 KB
最終ジャッジ日時 2023-09-10 12:58:55
合計ジャッジ時間 14,199 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,344 KB
testcase_01 AC 73 ms
71,408 KB
testcase_02 AC 97 ms
76,476 KB
testcase_03 AC 77 ms
71,372 KB
testcase_04 AC 1,917 ms
78,692 KB
testcase_05 AC 1,922 ms
78,932 KB
testcase_06 AC 76 ms
71,260 KB
testcase_07 AC 102 ms
76,684 KB
testcase_08 AC 470 ms
77,384 KB
testcase_09 AC 240 ms
77,692 KB
testcase_10 AC 123 ms
77,672 KB
testcase_11 AC 972 ms
77,896 KB
testcase_12 AC 498 ms
77,644 KB
testcase_13 AC 75 ms
75,192 KB
testcase_14 AC 106 ms
77,420 KB
testcase_15 AC 85 ms
76,188 KB
testcase_16 AC 362 ms
77,732 KB
testcase_17 AC 250 ms
77,628 KB
testcase_18 AC 579 ms
77,772 KB
testcase_19 AC 238 ms
77,936 KB
testcase_20 AC 984 ms
78,144 KB
testcase_21 AC 985 ms
78,068 KB
testcase_22 AC 1,799 ms
78,640 KB
testcase_23 AC 530 ms
77,692 KB
testcase_24 AC 188 ms
77,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

Directions = [(1, 0), (0, 1)]
ans = 0
ans_bit = -1
for bit in range(1 << k):
    DP = [[0 for _ in range(w + 1)] for _ in range(h + 1)]
    DP[0][0] = 1
    cnt = 0
    for i in range(k):
        if (bit >> i) & 1:
            cnt += 1
        else:
            x, y = P[i]
            DP[x][y] = -1
    if cnt > p:
        continue
    for i in range(h + 1):
        for j in range(w + 1):
            if DP[i][j] > 0:
                for di, dj in Directions:
                    ni, nj = i + di, j + dj
                    if ni <= h and nj <= w and DP[ni][nj] != -1:
                        DP[ni][nj] += DP[i][j]
    if DP[h][w] > ans:
        ans = DP[h][w]
        ans_bit = bit

mod = 10**9 + 7
print(ans % mod)
if ans > 0:
    for i in range(k):
        if (ans_bit >> i) & 1:
            print(N[i])
0