結果

問題 No.52 よくある文字列の問題
ユーザー @abcde@abcde
提出日時 2019-03-30 15:34:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 992 bytes
コンパイル時間 1,609 ms
コンパイル使用メモリ 168,868 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 04:17:55
合計ジャッジ時間 2,344 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    
    // 1. 入力情報取得.
    string S;
    cin >> S;
    
    // 2. 文字列長保存.
    int l = S.size();
    
    // 3. 文字列保存用.
    map<string, int> m;
    
    // 4. 探索.
    for(int i = 0; i < (1 << l); i++){
        // ex.
        // i = 5 ならば, 101 で, 考える.
        // -> 0: 先頭文字, 1: 末尾文字 と見做す.
        string ts = S;
        for(int j = 0; j < l; j++){
            if((i >> j) & 1 == 1){
                // 文字列の末尾を取得.
                char b = ts.back();
                // 取得した文字を, j番目に追加.
                ts.insert(ts.begin() + j, b);
                // 文字列の末尾削除.
                ts.pop_back();
            }
        }
        m[ts]++;
    }
    // for(auto &p : m) cout << p.first << ": "<< p.second << endl;
    
    // 5. 出力.
    int ans = m.size();
    cout << ans << endl;
    return 0;
    
}
0