結果

問題 No.506 限られたジャパリまん
ユーザー h_nosonh_noson
提出日時 2017-06-15 22:51:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 12,796 KB
最終ジャッジ日時 2023-09-10 12:54:33
合計ジャッジ時間 3,688 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,236 KB
testcase_01 AC 15 ms
8,176 KB
testcase_02 AC 22 ms
8,084 KB
testcase_03 AC 16 ms
8,168 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def popcount(x):
    ret = 0
    while x:
        x &= x-1
        ret += 1
    return ret

MOD = 10**9+7

h, w, k, p = map(int,input().split(' '))
x = [0] * k
y = [0] * k
n = [""] * k
m = [[True] * (w+1) for i in range(h+1)]
for i in range(k):
    a,b,n[i] = input().split(' ')
    x[i] = int(a)
    y[i] = int(b)
    m[x[i]][y[i]] = False

mx = 0
bits = -1
for i in range(1<<k):
    if popcount(i) <= p:
        for j in range(k):
            if i&1<<j:
                m[x[j]][y[j]] = True
        s = [[0] * (w+1) for i in range(h+1)]
        s[0][0] = 1
        for a in range(h+1):
            for b in range(w+1):
                if a < h and m[a+1][b]:
                    s[a+1][b] += s[a][b]
                    s[a+1][b] %= MOD
                if b < w and m[a][b+1]:
                    s[a][b+1] += s[a][b]
                    s[a][b+1] %= MOD
        if s[h][w] > mx:
            mx = s[h][w]
            bits = i
        for j in range(k):
            if i&1<<j:
                m[x[j]][y[j]] = False
print(mx)
if bits >= 0:
    for j in range(k):
        if bits&1<<j:
            print(n[j])
0