結果

問題 No.506 限られたジャパリまん
ユーザー fiordfiord
提出日時 2017-07-12 07:48:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,015 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 86,408 KB
実行使用メモリ 78,144 KB
最終ジャッジ日時 2023-09-10 12:55:09
合計ジャッジ時間 9,206 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
70,712 KB
testcase_01 AC 73 ms
71,004 KB
testcase_02 AC 88 ms
75,736 KB
testcase_03 AC 74 ms
70,968 KB
testcase_04 AC 1,009 ms
77,932 KB
testcase_05 AC 1,015 ms
78,144 KB
testcase_06 AC 76 ms
71,112 KB
testcase_07 AC 97 ms
76,596 KB
testcase_08 AC 294 ms
77,836 KB
testcase_09 AC 190 ms
77,336 KB
testcase_10 AC 121 ms
77,332 KB
testcase_11 AC 600 ms
77,640 KB
testcase_12 AC 314 ms
77,656 KB
testcase_13 AC 76 ms
70,980 KB
testcase_14 AC 100 ms
76,652 KB
testcase_15 AC 75 ms
70,976 KB
testcase_16 AC 273 ms
77,284 KB
testcase_17 AC 183 ms
77,548 KB
testcase_18 AC 373 ms
77,404 KB
testcase_19 AC 130 ms
77,280 KB
testcase_20 AC 600 ms
77,556 KB
testcase_21 AC 601 ms
77,444 KB
testcase_22 AC 951 ms
78,028 KB
testcase_23 AC 326 ms
77,312 KB
testcase_24 AC 117 ms
76,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w, k, p = map(int, input().split())
dat = []
for i in range(k):
    x, y, n = input().split()
    x = int(x)
    y = int(y)
    dat.append([x, y, n])
ret = 0
num = 0
for i in range(1 << k):
    if p < bin(i).count("1"):
        continue
    cnt = [[0] * (w + 1) for j in range(h + 1)]
    cnt[0][0] = 1
    for j in range(k):
        if not (i >> j) & 1:
            cnt[dat[j][0]][dat[j][1]] = -1
    for x in range(h + 1):
        for y in range(w + 1):
            if cnt[x][y] == -1:
                continue
            if x + 1 <= h and cnt[x + 1][y] != -1:
                cnt[x + 1][y] += cnt[x][y]
            if y + 1 <= w and cnt[x][y + 1] != -1:
                cnt[x][y + 1] += cnt[x][y]
    if cnt[h][w] > num:
        num = cnt[h][w]
        ret = i
print(num % (10**9 + 7))
for i in range(k):
    if (ret >> i) & 1:
        print(dat[i][2])
0