結果
問題 |
No.430 文字列検索
|
ユーザー |
|
提出日時 | 2018-09-26 12:12:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 211 ms / 2,000 ms |
コード長 | 995 bytes |
コンパイル時間 | 668 ms |
コンパイル使用メモリ | 72,296 KB |
実行使用メモリ | 7,684 KB |
最終ジャッジ日時 | 2024-11-10 00:20:08 |
合計ジャッジ時間 | 3,310 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
#include<iostream> #include<vector> using namespace std; typedef long long ll; int main(){ ll times[10] = {}; times[0] = 1; for(int i = 1; i < 10; i++){ times[i] = times[i-1]*26; } string s; cin >> s; int n = s.length(); vector<vector<ll>> hash(11); for(int i = 1; i <= min(n, 10); i++){ ll roll = 0; for(int j = 0; j < i; j++) roll = roll*26 + s[j]-'A'; hash[i].push_back(roll); for(int j = i; j < n; j++){ roll %= times[i-1]; roll *= 26; roll += s[j]-'A'; hash[i].push_back(roll); } } int m; cin >> m; string c; int ans = 0; for(int i = 0; i < m; i++){ cin >> c; int clen = c.length(); ll target = 0; for(int j = 0; j < clen; j++){ target = target*26 + (c[j]-'A'); } for(ll h : hash[clen]) ans += (target == h); } cout << ans << endl; return 0; }