結果

問題 No.170 スワップ文字列(Easy)
ユーザー Navier_Boltzmann
提出日時 2022-03-11 02:09:19
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 249 ms / 5,000 ms
コード長 511 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 16,140 KB
最終ジャッジ日時 2024-09-15 02:03:11
合計ジャッジ時間 2,620 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

S = list(input())
from collections import defaultdict
d = defaultdict(lambda:0)
ans = 0
from collections import deque
v = deque()
v.append(tuple(S))
def candidate(X):
    T = list(X)
    tmp = []
    n = len(T)
    for i in range(n-1):
        a = T[:]
        a[i],a[i+1] = a[i+1],a[i]
        tmp.append(tuple(a))
    return tmp
ans = 0
d[tuple(S)] = 1
while v:
    x = v.popleft()
    for ix in candidate(x):
        if d[ix]==0:
            d[ix] = 1
            ans += 1
            v.append(ix)
print(ans)
0