結果

問題 No.52 よくある文字列の問題
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-02-24 17:54:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 1,029 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 80,612 KB
実行使用メモリ 57,716 KB
最終ジャッジ日時 2023-10-22 04:17:35
合計ジャッジ時間 4,440 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,480 KB
testcase_01 AC 127 ms
57,484 KB
testcase_02 AC 139 ms
57,684 KB
testcase_03 AC 128 ms
57,476 KB
testcase_04 AC 128 ms
56,396 KB
testcase_05 AC 140 ms
57,620 KB
testcase_06 AC 139 ms
57,656 KB
testcase_07 AC 139 ms
57,684 KB
testcase_08 AC 133 ms
57,716 KB
testcase_09 AC 130 ms
57,212 KB
testcase_10 AC 128 ms
57,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        String s = stdin.nextLine();
        
        Deque<String> q1 = new ArrayDeque<>();
        Deque<String> q2 = new ArrayDeque<>();
        Set<String> set = new HashSet<>();
        
        q1.add(s);
        q2.add("");
        
        while (!q1.isEmpty()) {
            String s1 = q1.pollFirst(); // 残り
            String s2 = q2.pollFirst(); // 完成した文字列
            
            if (s1.isEmpty()) {
                set.add(s2);
            } else {
                q1.add(s1.substring(1));
                q2.add(s2 + s1.substring(0, 1));
                
                q1.add(s1.substring(0, s1.length() - 1));
                q2.add(s2 + s1.substring(s1.length() - 1));
            }
        }
        
        System.out.println(set.size());
    }
}
0