結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
70,864 KB
testcase_01 AC 70 ms
70,728 KB
testcase_02 AC 84 ms
75,648 KB
testcase_03 AC 71 ms
70,936 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 69 ms
70,856 KB
testcase_07 WA -
testcase_08 AC 278 ms
77,560 KB
testcase_09 AC 171 ms
77,412 KB
testcase_10 AC 118 ms
77,136 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 74 ms
71,020 KB
testcase_14 WA -
testcase_15 AC 73 ms
70,812 KB
testcase_16 AC 239 ms
77,488 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 104 ms
77,024 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
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 mx > 0:
    for j in range(k):
        if bits&1<<j:
            print(n[j])
0