結果
問題 | No.2178 Payable Magic Items |
ユーザー |
![]() |
提出日時 | 2023-06-08 19:22:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,050 ms / 4,000 ms |
コード長 | 1,034 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 82,344 KB |
実行使用メモリ | 149,792 KB |
最終ジャッジ日時 | 2024-12-31 03:42:47 |
合計ジャッジ時間 | 12,285 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
# 公式解説のBFS que visitedを自分のアイディアと合体 # 数字と見なして降順ソート # 大きい方から見ていって、その下部にある数字をBFS queしてvisited add # visitedに入らなかったものをNから引けば答え # 5**8=400000をどんどん埋めていくので二重ループにならないのだと思う N, K = map(int, input().split()) S = [] for i in range(N): S.append(input()) S.sort(reverse = True) #print(S) 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)