結果

問題 No.430 文字列検索
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-11-21 13:40:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 77,072 KB
実行使用メモリ 30,960 KB
最終ジャッジ日時 2024-04-17 23:55:35
合計ジャッジ時間 1,938 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 191 ms
30,960 KB
testcase_02 AC 9 ms
8,072 KB
testcase_03 AC 8 ms
8,272 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 172 ms
30,764 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 64 ms
11,696 KB
testcase_12 AC 60 ms
11,972 KB
testcase_13 AC 63 ms
11,920 KB
testcase_14 AC 50 ms
10,272 KB
testcase_15 AC 38 ms
9,572 KB
testcase_16 AC 11 ms
8,172 KB
testcase_17 AC 10 ms
8,280 KB
権限があれば一括ダウンロードができます

ソースコード

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<=min(n-i,10);++j) {
            hash[i][j] = hash[i][j-1] * BASE + ll(s[i+j-1]-'A');
        }
    }

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

    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