結果

問題 No.52 よくある文字列の問題
ユーザー YamaKasaYamaKasa
提出日時 2018-06-24 21:38:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 1,028 bytes
コンパイル時間 2,844 ms
コンパイル使用メモリ 77,608 KB
実行使用メモリ 57,716 KB
最終ジャッジ日時 2023-10-22 04:15:34
合計ジャッジ時間 4,598 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
57,264 KB
testcase_01 AC 134 ms
57,588 KB
testcase_02 AC 146 ms
57,308 KB
testcase_03 AC 136 ms
57,480 KB
testcase_04 AC 144 ms
57,452 KB
testcase_05 AC 143 ms
57,716 KB
testcase_06 AC 145 ms
57,592 KB
testcase_07 AC 139 ms
57,296 KB
testcase_08 AC 133 ms
57,628 KB
testcase_09 AC 134 ms
57,448 KB
testcase_10 AC 133 ms
57,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	static int[] bit;
	static String[] a;
	static Set<String> set;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		a = S.split("");
		bit = new int[a.length];
		set = new HashSet<String>();
		rec(0);
		System.out.println(set.size());

	}
	static void solve() {
		int l = 0;
		int r = a.length - 1;
		String []t = new String[bit.length];
		for(int i = 0; i < bit.length; i++) {
			if(bit[i] == 0) {
				t[i] = a[l];
				l ++;
			}else {
				t[i] = a[r];
				r --;
			}

		}
		set.add(con(t));
	}
	public static void rec(int k) {
        if(k == bit.length) {
        	solve();
            return;
        }
        rec(k + 1);
        bit[k] = 1;
        rec(k + 1);
        bit[k] = 0;
    }
	static String con(String[] s) {
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < s.length; i++) {
			sb.append(s[i]);
		}
		return sb.toString();
	}
}
0