結果

問題 No.170 スワップ文字列(Easy)
ユーザー hhgfhn1hhgfhn1
提出日時 2018-10-19 12:06:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,211 ms / 5,000 ms
コード長 745 bytes
コンパイル時間 1,864 ms
コンパイル使用メモリ 75,068 KB
実行使用メモリ 59,028 KB
最終ジャッジ日時 2024-04-28 12:31:41
合計ジャッジ時間 13,146 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
41,124 KB
testcase_01 AC 2,196 ms
59,028 KB
testcase_02 AC 116 ms
41,300 KB
testcase_03 AC 130 ms
41,560 KB
testcase_04 AC 273 ms
47,240 KB
testcase_05 AC 2,137 ms
58,976 KB
testcase_06 AC 2,211 ms
59,012 KB
testcase_07 AC 132 ms
41,296 KB
testcase_08 AC 178 ms
45,400 KB
testcase_09 AC 187 ms
45,216 KB
testcase_10 AC 1,179 ms
54,476 KB
testcase_11 AC 108 ms
41,172 KB
testcase_12 AC 114 ms
41,656 KB
testcase_13 AC 113 ms
41,420 KB
testcase_14 AC 107 ms
41,200 KB
testcase_15 AC 210 ms
46,236 KB
testcase_16 AC 109 ms
41,360 KB
testcase_17 AC 110 ms
40,928 KB
testcase_18 AC 133 ms
41,660 KB
testcase_19 AC 117 ms
41,236 KB
testcase_20 AC 122 ms
41,512 KB
testcase_21 AC 106 ms
41,284 KB
testcase_22 AC 137 ms
42,180 KB
testcase_23 AC 105 ms
41,192 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