結果

問題 No.2178 Payable Magic Items
ユーザー FromBooska
提出日時 2023-06-08 19:17:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,115 ms / 4,000 ms
コード長 728 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 82,644 KB
実行使用メモリ 149,764 KB
最終ジャッジ日時 2024-12-31 03:38:31
合計ジャッジ時間 13,770 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

# 解説のコンセプトから自分でやってみる

N, K = map(int, input().split())
S = []
for i in range(N):
    S.append(input())
S.sort(reverse = True)

from collections import deque
visited = set()
count = 0
for s in S:
    if s in visited:
        continue
    count += 1
    que = deque()
    que.append(s)
    while que:
        current = que.popleft()
        #print('s', s, 'current', current, 'que', que)
        
        for k in range(K):
            if int(current[k]) > 0:
                new = current[:k] + str(int(current[k])-1) + current[k+1:]
                if new not in visited:
                    visited.add(new)
                    que.append(new)
#print(count)

ans = N - count
print(ans)





0