結果
問題 | No.430 文字列検索 |
ユーザー |
![]() |
提出日時 | 2016-10-02 23:09:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 501 ms / 2,000 ms |
コード長 | 1,016 bytes |
コンパイル時間 | 632 ms |
コンパイル使用メモリ | 66,116 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-10 00:03:14 |
合計ジャッジ時間 | 6,020 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <cstdio> #include <set> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) const int INF = 1e9; string c[5010]; typedef unsigned long long ull; const ull B = 100000007; //aはbにいくつ int contain(string a, string b){ // cout << a << " "<< b << endl; int ret = 0; int al = a.length(), bl = b.length(); // printf("%d %d\n", al, bl); if(al > bl) return 0; ull t = 1; for (int i = 0; i < al; ++i) t *= B; ull ah = 0, bh = 0; for (int i = 0; i < al; ++i) ah = ah * B + a[i]; for (int i = 0; i < al; ++i) bh = bh * B + b[i]; for (int i = 0; i + al <= bl; ++i){ if(ah == bh) ret++; if(i + al < bl) bh = bh * B + b[i + al] - b[i] * t; } // printf("ret %d\n", ret); return ret; } int main(void){ string s; cin >> s; int m; cin >> m; rep(i, m) cin >> c[i]; ll ans = 0; rep(i, m){ // printf("m %d\n", m); ans += contain(c[i], s); } printf("%lld\n", ans); return 0; }