結果

問題 No.506 限られたジャパリまん
ユーザー h_nosonh_noson
提出日時 2017-06-15 22:49:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 1,138 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 78,252 KB
最終ジャッジ日時 2023-09-10 12:54:33
合計ジャッジ時間 9,473 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,144 KB
testcase_01 AC 74 ms
71,208 KB
testcase_02 AC 89 ms
76,184 KB
testcase_03 AC 73 ms
71,204 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 74 ms
71,036 KB
testcase_07 WA -
testcase_08 AC 285 ms
77,680 KB
testcase_09 AC 175 ms
77,696 KB
testcase_10 AC 121 ms
77,260 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 73 ms
71,312 KB
testcase_14 WA -
testcase_15 AC 74 ms
71,448 KB
testcase_16 AC 237 ms
77,848 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 106 ms
77,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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]
                if b < w and m[a][b+1]:
                    s[a][b+1] += s[a][b]
        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