結果

問題 No.430 文字列検索
ユーザー ふーらくたるふーらくたる
提出日時 2016-10-02 23:48:10
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 797 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 66,456 KB
実行使用メモリ 10,780 KB
最終ジャッジ日時 2024-05-01 10:57:35
合計ジャッジ時間 4,201 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 235 ms
5,376 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 <iostream>
#include <vector>
using namespace std;

using ll = long long;

vector<int> alpha_index[26];
vector<string> strs[26];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    int m;
    cin >> s;
    cin >> m;

    for (int i = 0; i < m; i++) {
        string c;
        cin >> c;
        strs[c[0] - 'A'].push_back(c);
    }

    for (int i = 0; i < s.size(); i++) {
        alpha_index[s[i] - 'A'].push_back(i);
    }

    ll ans = 0;
    for (int i = 0; i < 26; i++) {
        // 'A' + iを調べる
        for (auto idx : alpha_index[i]) {
            for (auto str : strs[i]) {
                string temp = s.substr(idx, str.size());
                if (temp == str) ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0