結果

問題 No.430 文字列検索
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-11-21 13:36:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 855 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 76,708 KB
実行使用メモリ 30,540 KB
最終ジャッジ日時 2024-04-17 23:49:39
合計ジャッジ時間 7,247 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <map>

using namespace std;

using ll =  long long;

constexpr ll BASE = 26;

int main() {
    string s;
    cin >> s;
    int n = s.length();

    ll hash[n][11];
    for(int i=0;i<n;++i){
        hash[i][1] = ll(s[i]-'A');
        for(int j=2;j<=n-i;++j) {
            hash[i][j] = hash[i][j-1] * BASE + ll(s[i+j-1]-'A');
        }
    }

    map<ll, int> hash_cnt[11];
    for(int i=1;i<=11;++i) {
        for(int j=0;j<n;++j) {
            ++hash_cnt[i][hash[j][i]];
        }
    }

    int m, cnt = 0;
    cin >> m;
    string c;
    for(int i=0;i<m;++i){
        cin >> c;
        int nc = c.length();
        ll c_hash = ll(c[0]-'A');
        for(int j=1;j<nc;++j) {
            c_hash = c_hash * BASE + ll(c[j]-'A');
        }

        cnt += hash_cnt[nc][c_hash];
    }

    cout << cnt << endl;
}
0