結果

問題 No.170 スワップ文字列(Easy)
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-03-11 02:09:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 218 ms / 5,000 ms
コード長 511 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 14,024 KB
最終ジャッジ日時 2023-10-13 04:30:50
合計ジャッジ時間 2,483 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,412 KB
testcase_01 AC 218 ms
14,020 KB
testcase_02 AC 18 ms
8,356 KB
testcase_03 AC 19 ms
8,320 KB
testcase_04 AC 22 ms
8,516 KB
testcase_05 AC 214 ms
13,908 KB
testcase_06 AC 215 ms
14,024 KB
testcase_07 AC 19 ms
8,380 KB
testcase_08 AC 19 ms
8,304 KB
testcase_09 AC 18 ms
8,416 KB
testcase_10 AC 114 ms
11,020 KB
testcase_11 AC 19 ms
8,456 KB
testcase_12 AC 18 ms
8,512 KB
testcase_13 AC 18 ms
8,360 KB
testcase_14 AC 18 ms
8,416 KB
testcase_15 AC 20 ms
8,416 KB
testcase_16 AC 18 ms
8,380 KB
testcase_17 AC 19 ms
8,380 KB
testcase_18 AC 18 ms
8,416 KB
testcase_19 AC 19 ms
8,428 KB
testcase_20 AC 19 ms
8,504 KB
testcase_21 AC 18 ms
8,376 KB
testcase_22 AC 19 ms
8,488 KB
testcase_23 AC 19 ms
8,416 KB
権限があれば一括ダウンロードができます

ソースコード

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