結果

問題 No.52 よくある文字列の問題
ユーザー htensaihtensai
提出日時 2019-12-06 21:05:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 165 ms / 5,000 ms
コード長 718 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 80,968 KB
実行使用メモリ 57,256 KB
最終ジャッジ日時 2023-08-25 12:48:31
合計ジャッジ時間 4,937 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
56,956 KB
testcase_01 AC 151 ms
56,724 KB
testcase_02 AC 162 ms
56,964 KB
testcase_03 AC 148 ms
57,064 KB
testcase_04 AC 165 ms
56,724 KB
testcase_05 AC 165 ms
57,060 KB
testcase_06 AC 163 ms
56,864 KB
testcase_07 AC 160 ms
56,868 KB
testcase_08 AC 151 ms
57,256 KB
testcase_09 AC 149 ms
56,780 KB
testcase_10 AC 149 ms
56,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static HashSet<String> set = new HashSet<>();
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		search(arr, "", 0, arr.length, true);
		search(arr, "", -1, arr.length - 1, false);
		System.out.println(set.size());
   }
   
   static void search(char[] arr, String str, int left, int right, boolean isLeft) {
       if (left == right) {
           set.add(str);
           return;
       }
       if (isLeft) {
           str += arr[left];
       } else {
           str += arr[right];
       }
       search(arr, str, left + 1, right, true);
       search(arr, str, left, right - 1, false);
   }
}

0