結果

問題 No.170 スワップ文字列(Easy)
ユーザー nCk_cvnCk_cv
提出日時 2016-02-18 15:46:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 959 ms / 5,000 ms
コード長 769 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 79,016 KB
実行使用メモリ 86,316 KB
最終ジャッジ日時 2023-10-23 18:05:54
合計ジャッジ時間 9,503 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
57,160 KB
testcase_01 AC 959 ms
86,156 KB
testcase_02 AC 122 ms
57,152 KB
testcase_03 AC 125 ms
55,520 KB
testcase_04 AC 165 ms
60,068 KB
testcase_05 AC 934 ms
86,316 KB
testcase_06 AC 908 ms
85,676 KB
testcase_07 AC 123 ms
57,464 KB
testcase_08 AC 140 ms
55,364 KB
testcase_09 AC 144 ms
57,340 KB
testcase_10 AC 610 ms
80,080 KB
testcase_11 AC 125 ms
57,436 KB
testcase_12 AC 122 ms
57,460 KB
testcase_13 AC 113 ms
56,168 KB
testcase_14 AC 119 ms
57,388 KB
testcase_15 AC 150 ms
59,600 KB
testcase_16 AC 110 ms
56,184 KB
testcase_17 AC 124 ms
57,080 KB
testcase_18 AC 113 ms
56,184 KB
testcase_19 AC 122 ms
57,168 KB
testcase_20 AC 110 ms
56,184 KB
testcase_21 AC 122 ms
57,436 KB
testcase_22 AC 126 ms
57,528 KB
testcase_23 AC 124 ms
57,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.awt.geom.*;
import java.io.*;

class Main {
	static HashMap<String,Boolean> map = new HashMap<String,Boolean>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.next();
		dfs(new StringBuilder(in));
		System.out.println(map.size()-1);
	}
	static void dfs(StringBuilder a) {
		if(map.containsKey(a.toString())) return;
		map.put(a.toString(), true);
		for(int i = 0; i < a.length(); i++) {
			for(int j = i+1; j < a.length(); j++) {
				char b = a.charAt(i);
				a = a.replace(i, i+1, String.valueOf(a.charAt(j)));
				a = a.replace(j, j+1, String.valueOf(b));
				dfs(a);
				a = a.replace(j, j+1, String.valueOf(a.charAt(i)));
				a = a.replace(i, i+1, String.valueOf(b));
			}
		}
	}
}
0