結果

問題 No.52 よくある文字列の問題
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-19 00:28:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 1,241 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 80,344 KB
実行使用メモリ 57,688 KB
最終ジャッジ日時 2023-10-22 03:59:05
合計ジャッジ時間 4,250 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
56,256 KB
testcase_01 AC 118 ms
57,184 KB
testcase_02 AC 138 ms
57,656 KB
testcase_03 AC 118 ms
57,604 KB
testcase_04 AC 130 ms
57,688 KB
testcase_05 AC 128 ms
57,564 KB
testcase_06 AC 135 ms
57,652 KB
testcase_07 AC 131 ms
57,380 KB
testcase_08 AC 119 ms
57,500 KB
testcase_09 AC 110 ms
57,504 KB
testcase_10 AC 126 ms
57,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.regex.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        String s = koko.next();
        int n = s.length();
        int keta = (int)Math.pow(2,n-1);
        char[][] answe = new char[keta][n];
        String[] answer = new String[keta];
        for(int i=0; i<keta; i++){
            String a = Integer.toBinaryString(i);
            while(a.length()<n-1){
                a="0"+a;
            }
            int sentou = 0;
            int matsubi = n-1;
            for(int j=0; j<n-1; j++){
                if(a.charAt(j)=='0'){
                    answe[i][j]=s.charAt(sentou);
                    sentou++;
                }else{
                    answe[i][j]=s.charAt(matsubi);
                    matsubi--;
                }
                answe[i][n-1]=s.charAt(sentou);
                answer[i]=String.valueOf(answe[i]);
            }
        }
        Arrays.sort(answer);
        int ans=1;
        for(int i=1; i<keta; i++){
            if(answer[i].equals(answer[i-1])){
                
            }else{
                ans++;
            }
        }
        System.out.println(ans);
    }
}

0