結果

問題 No.170 スワップ文字列(Easy)
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-19 12:06:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,348 ms / 5,000 ms
コード長 745 bytes
コンパイル時間 3,126 ms
コンパイル使用メモリ 72,964 KB
実行使用メモリ 71,508 KB
最終ジャッジ日時 2023-08-10 19:11:15
合計ジャッジ時間 15,522 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
55,692 KB
testcase_01 AC 2,281 ms
71,508 KB
testcase_02 AC 112 ms
56,052 KB
testcase_03 AC 140 ms
56,424 KB
testcase_04 AC 248 ms
60,428 KB
testcase_05 AC 2,249 ms
71,316 KB
testcase_06 AC 2,348 ms
71,236 KB
testcase_07 AC 141 ms
56,620 KB
testcase_08 AC 177 ms
59,716 KB
testcase_09 AC 166 ms
59,868 KB
testcase_10 AC 1,310 ms
68,888 KB
testcase_11 AC 107 ms
55,896 KB
testcase_12 AC 117 ms
56,292 KB
testcase_13 AC 115 ms
56,144 KB
testcase_14 AC 108 ms
56,136 KB
testcase_15 AC 192 ms
60,332 KB
testcase_16 AC 119 ms
55,444 KB
testcase_17 AC 118 ms
56,104 KB
testcase_18 AC 147 ms
56,132 KB
testcase_19 AC 117 ms
55,720 KB
testcase_20 AC 111 ms
55,736 KB
testcase_21 AC 114 ms
55,744 KB
testcase_22 AC 153 ms
55,128 KB
testcase_23 AC 113 ms
56,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String s=scanner.next();
		dfs(s);
		System.out.println(set.size()-1);
		
	}
	static Set<String>set=new HashSet<>();
	private static void dfs(String s) {
		if(set.contains(s)){
			return;
		}else{
			set.add(s);
		}
		for(int i=0;i<s.length()-1;i++){
			for(int j=i+1;j<s.length();j++){
				String st=swap(s,i,j);
				dfs(st);
			}
		}
		
	}

	private static String swap(String s, int i, int j) {
		String string[]=s.split("");
		String tmp=string[i];
		string[i]=string[j];
		string[j]=tmp;
		return String.join("", string);
	}
}
0