結果

問題 No.2178 Payable Magic Items
ユーザー minimumminimum
提出日時 2023-01-06 22:08:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 832 ms / 4,000 ms
コード長 832 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 179,844 KB
最終ジャッジ日時 2023-08-21 08:17:10
合計ジャッジ時間 10,575 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,468 KB
testcase_01 AC 86 ms
71,040 KB
testcase_02 AC 90 ms
71,572 KB
testcase_03 AC 89 ms
71,200 KB
testcase_04 AC 89 ms
71,144 KB
testcase_05 AC 614 ms
154,512 KB
testcase_06 AC 521 ms
157,288 KB
testcase_07 AC 90 ms
71,544 KB
testcase_08 AC 507 ms
154,264 KB
testcase_09 AC 203 ms
86,016 KB
testcase_10 AC 112 ms
77,604 KB
testcase_11 AC 789 ms
179,844 KB
testcase_12 AC 282 ms
103,412 KB
testcase_13 AC 832 ms
179,040 KB
testcase_14 AC 282 ms
103,256 KB
testcase_15 AC 276 ms
103,084 KB
testcase_16 AC 280 ms
103,336 KB
testcase_17 AC 776 ms
171,060 KB
testcase_18 AC 139 ms
78,296 KB
testcase_19 AC 147 ms
86,908 KB
testcase_20 AC 98 ms
77,296 KB
testcase_21 AC 110 ms
77,632 KB
testcase_22 AC 112 ms
77,616 KB
testcase_23 AC 99 ms
77,092 KB
testcase_24 AC 813 ms
169,584 KB
testcase_25 AC 712 ms
163,728 KB
testcase_26 AC 160 ms
90,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


N, K = map(int, input().split())
S = [input() for _ in range(N)]
num = dict()

for i in range(N):
    n = 0
    for j in range(K):
        n *= 5
        n += 4 - int(S[i][j])
    num[n] = i

if 0 in num:
    print(N - 1)
    exit()

dq = deque()
dq.append((0, 0))
done = [-1] * (5 ** K)

while dq:
    now, t = dq.popleft()
    if done[now] >= t:
        continue
    done[now] = t
    if now in num:
        t = 1
    a = []
    for i in range(K):
        a.append(now % 5)
        now //= 5
    a.reverse()
    for i in range(K):
        if a[i] == 4:
            continue
        a[i] += 1
        nxt = 0
        for j in range(K):
            nxt *= 5
            nxt += a[j]
        dq.append((nxt, t))
        a[i] -= 1


ans = 0
for n in num:
    if done[n] == 1:
        ans += 1
print(ans)
0