結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  OUDON | 
| 提出日時 | 2016-11-18 02:27:37 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 513 ms / 2,000 ms | 
| コード長 | 1,261 bytes | 
| コンパイル時間 | 1,577 ms | 
| コンパイル使用メモリ | 169,424 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-10 00:12:51 | 
| 合計ジャッジ時間 | 7,047 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
const ull B = 100000007;
int count(string a, string b)
{
    int al = a.size(), bl = b.size();
    if (bl > al) return 0;
    int res = 0;
    ull t = 1;
    for (int i=0; i<bl; i++) t *= B;
    ull ah = 0, bh = 0;
    rep(i, bl) ah = ah * B + a[i];
    rep(i, bl) bh = bh * B + b[i];
    for (int i=0; i+bl<=al; i++) {
        if (ah == bh) res++;
        if (i + bl < al) ah = ah * B + a[i + bl] - a[i] * t;
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(false);
    string S;
    int M;
    cin >> S >> M;
    int ans = 0;
    rep(i, M) {
        string C;
        cin >> C;
        ans += count(S, C);
    }
    cout << ans << endl;
}
            
            
            
        