結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,004 KB
testcase_01 AC 72 ms
71,156 KB
testcase_02 AC 94 ms
76,052 KB
testcase_03 AC 72 ms
70,716 KB
testcase_04 AC 944 ms
77,820 KB
testcase_05 AC 950 ms
77,980 KB
testcase_06 AC 73 ms
71,088 KB
testcase_07 AC 87 ms
76,128 KB
testcase_08 AC 279 ms
77,604 KB
testcase_09 AC 172 ms
77,284 KB
testcase_10 AC 124 ms
77,148 KB
testcase_11 AC 563 ms
77,156 KB
testcase_12 AC 298 ms
77,660 KB
testcase_13 AC 73 ms
70,948 KB
testcase_14 AC 100 ms
76,452 KB
testcase_15 AC 75 ms
71,040 KB
testcase_16 AC 238 ms
77,244 KB
testcase_17 AC 179 ms
77,308 KB
testcase_18 AC 353 ms
77,212 KB
testcase_19 AC 123 ms
77,432 KB
testcase_20 AC 554 ms
77,548 KB
testcase_21 AC 570 ms
77,468 KB
testcase_22 AC 893 ms
78,116 KB
testcase_23 AC 304 ms
77,436 KB
testcase_24 AC 102 ms
76,908 KB
権限があれば一括ダウンロードができます

ソースコード

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]
                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 % MOD)
if bits >= 0:
    for j in range(k):
        if bits&1<<j:
            print(n[j])
0