結果

問題 No.2178 Payable Magic Items
ユーザー FromBooskaFromBooska
提出日時 2023-06-08 19:17:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,168 ms / 4,000 ms
コード長 728 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 151,952 KB
最終ジャッジ日時 2023-08-29 23:51:47
合計ジャッジ時間 16,304 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,648 KB
testcase_01 AC 93 ms
71,612 KB
testcase_02 AC 93 ms
71,748 KB
testcase_03 AC 884 ms
138,552 KB
testcase_04 AC 93 ms
71,740 KB
testcase_05 AC 106 ms
77,556 KB
testcase_06 AC 149 ms
78,720 KB
testcase_07 AC 94 ms
71,612 KB
testcase_08 AC 146 ms
78,956 KB
testcase_09 AC 142 ms
78,536 KB
testcase_10 AC 95 ms
71,540 KB
testcase_11 AC 771 ms
109,396 KB
testcase_12 AC 1,144 ms
151,596 KB
testcase_13 AC 1,166 ms
148,736 KB
testcase_14 AC 1,153 ms
151,952 KB
testcase_15 AC 1,161 ms
151,764 KB
testcase_16 AC 1,168 ms
151,796 KB
testcase_17 AC 955 ms
138,292 KB
testcase_18 AC 144 ms
78,844 KB
testcase_19 AC 295 ms
88,708 KB
testcase_20 AC 112 ms
77,676 KB
testcase_21 AC 138 ms
78,816 KB
testcase_22 AC 132 ms
78,664 KB
testcase_23 AC 116 ms
78,028 KB
testcase_24 AC 1,089 ms
147,184 KB
testcase_25 AC 927 ms
137,936 KB
testcase_26 AC 311 ms
88,356 KB
権限があれば一括ダウンロードができます

ソースコード

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