結果

問題 No.430 文字列検索
ユーザー @abcde@abcde
提出日時 2019-06-06 22:58:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,029 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 167,816 KB
実行使用メモリ 10,780 KB
最終ジャッジ日時 2024-04-09 20:41:44
合計ジャッジ時間 5,291 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,532 KB
testcase_01 AC 130 ms
6,812 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    
    // 1. 入力情報取得.
    string S;
    int M;
    cin >> S >> M;
    
    // 2. 文字列S について, i文字目 の アルファベット情報(位置) を 保存
    const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    vector<vector<int>> pos(26);
    for(int i = 0; i < S.size(); i++) pos[S[i] - 'A'].push_back(i);
    // for(auto &v : pos){
    //     for(auto &p : v) cout << p << " ";
    //     cout << endl;
    // }
    
    // 3. すべての部分文字列の数をカウント.
    int ans = 0;
    for(int i = 0; i < M; i++){
        string C;
        cin >> C;
        // 先頭文字 に 対応するインデックスを取得.
        int index = C[0] - 'A';
        int l = C.size();
        // 文字列S の 部分文字列 と 比較して, 等しい場合は, インクリメント.
        for(auto &v : pos[index]) if(C == S.substr(v, l)) ans++;
    }
    
    // 4. 後処理.
    cout << ans << endl;
    return 0;
    
}
0