結果
| 問題 | No.52 よくある文字列の問題 | 
| コンテスト | |
| ユーザー |  neko_the_shadow | 
| 提出日時 | 2019-02-24 17:54:43 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 137 ms / 5,000 ms | 
| コード長 | 1,029 bytes | 
| コンパイル時間 | 2,269 ms | 
| コンパイル使用メモリ | 80,364 KB | 
| 実行使用メモリ | 54,320 KB | 
| 最終ジャッジ日時 | 2024-09-22 05:38:36 | 
| 合計ジャッジ時間 | 4,348 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 | 
ソースコード
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());
    }
}
            
            
            
        