結果

問題 No.430 文字列検索
ユーザー cumincumin
提出日時 2021-01-10 17:37:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 509 ms / 2,000 ms
コード長 1,804 bytes
コンパイル時間 2,578 ms
コンパイル使用メモリ 201,596 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 05:02:09
合計ジャッジ時間 8,578 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 508 ms
5,376 KB
testcase_02 AC 505 ms
5,376 KB
testcase_03 AC 507 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 503 ms
5,376 KB
testcase_12 AC 506 ms
5,376 KB
testcase_13 AC 507 ms
5,376 KB
testcase_14 AC 509 ms
5,376 KB
testcase_15 AC 508 ms
5,376 KB
testcase_16 AC 504 ms
5,376 KB
testcase_17 AC 506 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define ld long double

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)

#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second

#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define endl '\n'
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1000000007;
//const int MOD=998244353;
const ll INF = 1e18+1;
const int inf = 1e9+1;
const double PI = acos(-1);
int dx[8] = {1, 0, -1,  0,  1, 1, -1, -1};
int dy[8] = {0, 1,  0, -1, -1, 1,  1, -1};
 
const int MAX = 310000;

int contain(string a, string b){
  //bがaに含まれているか
  int al = a.length(), bl = b.length();
  int res = 0;
  if(al < bl) return 0;
  ull t = 1;
  rep(i, bl) t *= MOD;
  ull ah = 0, bh = 0;
  rep(i, bl) ah = ah * MOD + a[i];
  rep(i, bl) bh = bh * MOD + b[i];
  for(int i = 0; i+bl <= al; i++){
    if(ah == bh) res++;
    if(i + bl < al) ah = ah * MOD + a[i+bl] - a[i]*t;
  }
  return res;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  cout << fixed << setprecision(10);
  
  string s;
  cin >> s;
  int q;
  cin >> q;
  ll ans = 0;
  while(q--){
    string t;
    cin >> t;
    ans += contain(s, t);
  }
  cout << ans << endl;
  return 0;
}
0