結果
問題 |
No.430 文字列検索
|
ユーザー |
![]() |
提出日時 | 2017-08-17 23:28:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,096 bytes |
コンパイル時間 | 1,369 ms |
コンパイル使用メモリ | 166,712 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-10 00:17:51 |
合計ジャッジ時間 | 2,083 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
コンパイルメッセージ
main.cpp:21:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 21 | main(){ | ^~~~
ソースコード
#include <bits/stdc++.h> #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef set<int> si; typedef pair<ll,ll> pll; const int inf = 1e9; const ll mod1 = 1e9+7; const ll mod2 = 999999937; int m; ll mod[2] = {mod1, mod2}; set<pll> sl; int il[50020]; pll h[11]; main(){ cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s >> m; FOR(i, 0, m){ string c; cin >> c; ll d[2] = {0, 0}; FOR(i, 0, c.size()){ int k = (c[i] - 'A') + 1; FOR(j, 0, 2){ d[j] = (d[j] * 28 + k) % mod[j]; } } sl.insert(pll(d[0], d[1])); } FOR(i, 0, 9){ il[i] = 27; } FOR(i, 9, s.size() + 9){ il[i] = (s[i - 9] - 'A') + 1; } ll ans = 0; FOR(i, 0, s.size() + 9){ FORR(j, 10, 1){ h[j].first = (h[j-1].first * 28 + il[i]) % mod[0]; h[j].second = (h[j-1].second * 28 + il[i]) % mod[1]; if(sl.find(h[j]) != sl.end()) ans++; } } cout << ans << endl; }