結果

問題 No.170 スワップ文字列(Easy)
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-12 12:57:50
言語 Go
(1.22.1)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 671 bytes
コンパイル時間 11,381 ms
コンパイル使用メモリ 207,164 KB
実行使用メモリ 9,256 KB
最終ジャッジ日時 2023-09-05 20:21:39
合計ジャッジ時間 12,915 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 45 ms
8,916 KB
testcase_02 AC 36 ms
8,384 KB
testcase_03 AC 35 ms
8,388 KB
testcase_04 AC 36 ms
8,380 KB
testcase_05 AC 46 ms
9,056 KB
testcase_06 AC 45 ms
9,180 KB
testcase_07 AC 5 ms
5,660 KB
testcase_08 AC 37 ms
8,484 KB
testcase_09 AC 37 ms
8,384 KB
testcase_10 AC 42 ms
9,256 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

func main() {
	var s string
	_, _ = fmt.Scan(&s)

	src := make([]string, 0)
	for _, c := range s {
		src = append(src, string(c))
	}

	p := make(map[string]int, 0)
	for _, str := range permutation170(src, "") {
		p[str]++
	}

	fmt.Println(len(p) - 1)
}

func permutation170(src []string, dst string) []string {
	r := make([]string, 0)
	for i, c := range src {
		if len(src)-1 == 0 {
			r = append(r, dst+string(c))
		} else {
			nSrc := make([]string, len(src[:i]))
			copy(nSrc, src[:i])
			nSrc = append(nSrc, src[i+1:]...)

			// fmt.Println(dst, i, c, src, nSrc)
			r = append(r, permutation170(nSrc, dst+string(c))...)
		}
	}
	return r
}
0