結果

問題 No.430 文字列検索
ユーザー keep_OCkeep_OC
提出日時 2020-04-04 05:56:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 503 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 167,876 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 05:26:29
合計ジャッジ時間 7,471 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define rep(i, s, n) for (Int i = s; i < (Int)(n); i++)
#define rrep(i, n, s) for (Int i = n - 1; i >= s; i--)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()
 
double EPS = 1e-10;
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;


// s の中に t が何回現れるか
typedef unsigned long long ull;
const ull B = 1e9+7;
Int string_count(string s, string t) {
    Int s_len = s.length();
    Int t_len = t.length();
    if (s_len < t_len) return 0;
    ull x = 1;
    rep(i, 0, t_len) x *= B;
    ull s_hash = 0, t_hash = 0;
    rep(i, 0, t_len) s_hash = s_hash * B + s[i];
    rep(i, 0, t_len) t_hash = t_hash * B + t[i];
    Int ret = 0;
    rep(i, 0, s_len - t_len + 1) {
        if (s_hash == t_hash) ret++;
        if (i + t_len < s_len) {
            s_hash = s_hash * B + s[i + t_len] - s[i] * x;
        }
    }
    return ret;
}

int main() {
    string s;
    cin >> s;
    Int m;
    cin >> m;
    vector<string> t(m);
    rep(i, 0, m) cin >> t[i];
    Int res = 0;
    rep(i, 0, m) {
        res += string_count(s, t[i]);
    }
    dump(res);
    return 0;
}
0