結果

問題 No.52 よくある文字列の問題
ユーザー rn4rurn4ru
提出日時 2016-04-14 07:33:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 5,000 ms
コード長 690 bytes
コンパイル時間 4,076 ms
コンパイル使用メモリ 78,540 KB
実行使用メモリ 58,492 KB
最終ジャッジ日時 2023-10-22 04:04:27
合計ジャッジ時間 4,200 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
58,344 KB
testcase_01 AC 140 ms
58,184 KB
testcase_02 AC 157 ms
58,396 KB
testcase_03 AC 135 ms
57,764 KB
testcase_04 AC 155 ms
58,400 KB
testcase_05 AC 166 ms
58,260 KB
testcase_06 AC 165 ms
58,460 KB
testcase_07 AC 137 ms
57,532 KB
testcase_08 AC 142 ms
58,492 KB
testcase_09 AC 108 ms
57,424 KB
testcase_10 AC 135 ms
58,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();

		Set<String> s = new HashSet<>();
		f(S, "", s);
		System.out.println(s.size());
	}

	private static void f(String remaining, String newString, Set<String> set) {
		if (remaining.length() == 1) {
			set.add(newString + remaining);
		} else {
			String str = remaining.substring(1);
			f(str, newString + remaining.charAt(0), set);
			String str2 = remaining.substring(0, remaining.length() - 1);
			f(str2, newString + remaining.charAt(remaining.length() - 1), set);
		}
	}

}
0