結果

問題 No.430 文字列検索
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-11-21 13:34:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 778 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 65,368 KB
実行使用メモリ 8,020 KB
最終ジャッジ日時 2023-07-30 22:36:53
合計ジャッジ時間 28,658 ms
ジャッジサーバーID
(参考情報)
judge5 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>

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');
        }
    }

    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');
        }

        for(int j=0;j<=n-nc;++j) {
            if(hash[j][nc] == c_hash) {
                ++cnt;
            }
        }
    }

    cout << cnt << endl;
}
0