結果

問題 No.52 よくある文字列の問題
ユーザー tsunabittsunabit
提出日時 2019-12-13 14:37:55
言語 Java19
(openjdk 21)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 794 bytes
コンパイル時間 4,349 ms
コンパイル使用メモリ 73,892 KB
実行使用メモリ 57,112 KB
最終ジャッジ日時 2023-09-09 09:22:30
合計ジャッジ時間 6,348 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
56,316 KB
testcase_01 AC 156 ms
56,340 KB
testcase_02 AC 184 ms
56,648 KB
testcase_03 AC 156 ms
56,608 KB
testcase_04 AC 173 ms
55,376 KB
testcase_05 AC 173 ms
57,028 KB
testcase_06 AC 173 ms
56,848 KB
testcase_07 AC 171 ms
56,652 KB
testcase_08 AC 160 ms
57,112 KB
testcase_09 AC 155 ms
56,872 KB
testcase_10 AC 155 ms
56,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No52 {
	private static Set<String> set = new HashSet<String>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		dfs("", s);
		System.out.println(set.size());
	}
	
	public static void dfs(String kiridasi, String zan_str) {
		//end
		if(zan_str.length() == 0) {
			set.add(kiridasi);
			return;
		}
		//mae
		String mae = kiridasi + zan_str.charAt(0);
		StringBuilder sb_mae = new StringBuilder(zan_str);
		dfs(mae, sb_mae.deleteCharAt(0).toString());
		//ushiro
		String ushiro = kiridasi + zan_str.charAt(zan_str.length() - 1);
		StringBuilder sb_ushiro = new StringBuilder(zan_str);
		dfs(ushiro, sb_ushiro.deleteCharAt(zan_str.length() - 1).toString());
		
	}
}
0