結果

問題 No.430 文字列検索
ユーザー ttakanottakano
提出日時 2017-12-06 10:09:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 902 bytes
コンパイル時間 3,300 ms
コンパイル使用メモリ 145,368 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 09:34:32
合計ジャッジ時間 8,124 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int contain(string a,string b){
  int al=a.length(),bl=b.length();
  if(al>bl)return false;
  ll t=1;
  REP(i,al)t*=mod;
  ll ah=0,bh=0;
  REP(i,al)ah=ah*mod+a[i];
  REP(i,al)bh=bh*mod+b[i];

  int cnt=0;
  for(int i=0;i+al<=bl;i++){
    if(ah==bh)cnt++;
    if(i+al<bl)bh=bh*mod+b[i+al]-b[i]*t;
  }
  return cnt;
}

int main(){
  string s;
  int m;
  string c[5010];
  cin>>s;
  cin>>m;
  REP(i,m)cin>>c[i];
  //print(s);///
  //printall(m,c);///
  ll ans=0;
  REP(i,m)ans+=contain(c[i],s);
  print(ans);
}
0