結果

問題 No.170 スワップ文字列(Easy)
ユーザー jp_stejp_ste
提出日時 2015-03-30 12:12:05
言語 Java19
(openjdk 21)
結果
AC  
実行時間 337 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 76,756 KB
実行使用メモリ 65,004 KB
最終ジャッジ日時 2023-08-24 16:12:29
合計ジャッジ時間 8,361 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
56,812 KB
testcase_01 AC 280 ms
65,004 KB
testcase_02 AC 187 ms
60,084 KB
testcase_03 AC 217 ms
59,972 KB
testcase_04 AC 254 ms
61,008 KB
testcase_05 AC 265 ms
63,748 KB
testcase_06 AC 277 ms
63,576 KB
testcase_07 AC 194 ms
59,988 KB
testcase_08 AC 243 ms
60,888 KB
testcase_09 AC 239 ms
60,960 KB
testcase_10 AC 337 ms
61,508 KB
testcase_11 AC 152 ms
56,832 KB
testcase_12 AC 154 ms
56,944 KB
testcase_13 AC 155 ms
56,860 KB
testcase_14 AC 155 ms
56,964 KB
testcase_15 AC 170 ms
56,980 KB
testcase_16 AC 152 ms
56,672 KB
testcase_17 AC 154 ms
56,692 KB
testcase_18 AC 169 ms
58,972 KB
testcase_19 AC 153 ms
56,652 KB
testcase_20 AC 153 ms
56,832 KB
testcase_21 AC 166 ms
56,824 KB
testcase_22 AC 168 ms
56,912 KB
testcase_23 AC 154 ms
56,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	static TreeSet<String> mStrList = new TreeSet<String>();
	static String S = null;
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		S = sc.next();
		
		String str = "";
		boolean[] used = new boolean[S.length()];
		
		solve(str, used);
		System.out.println(mStrList.size());
	}
	
	static void solve(String str, boolean[] used) {
		
		if(str.length() == S.length()) {
			if(!str.equals(S)) {
				mStrList.add(str);
			}
			return;
		}
		
		for(int i=0; i<used.length; i++) {
			if(used[i]) { continue; }
			
			String nextStr = str + S.charAt(i);
			boolean[] nextUsed = used.clone();
			nextUsed[i] = true;
			
			solve(nextStr, nextUsed);
		}
	}
}
0