結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
keep_OC
|
| 提出日時 | 2020-04-04 05:56:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 444 ms / 2,000 ms |
| コード長 | 1,240 bytes |
| コンパイル時間 | 1,471 ms |
| コンパイル使用メモリ | 169,156 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-10 00:42:06 |
| 合計ジャッジ時間 | 6,445 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#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;
}
keep_OC