結果

問題 No.430 文字列検索
ユーザー 0w10w1
提出日時 2016-12-04 10:53:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 864 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 167,032 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 14:06:12
合計ジャッジ時間 11,855 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef vector< int > vi;

const int BS = 311;
const int MOD7 = 1e9 + 7;

signed main(){
  string S; cin >> S;
  vi ph( S.size() + 1 );
  vi bspw( S.size() + 1 ); bspw[ 0 ] = 1;
  for( int i = 0; i < S.size(); ++i )
    ph[ i + 1 ] = ( 1LL * ph[ i ] * BS + S[ i ] ) % MOD7,
    bspw[ i + 1 ] = 1LL * bspw[ i ] * BS % MOD7;
  int M; cin >> M;
  int ans = 0;
  for( int i = 0; i < M; ++i ){
    string C; cin >> C;
    int hv = 0;
    for( int j = 0; j < C.size(); ++j )
      hv = ( 1LL * hv * BS + C[ j ] ) % MOD7;
    for( int j = C.size(); j <= S.size(); ++j )
      ans += hv == ( ( 1LL * ph[ j ] - 1LL * bspw[ C.size() ] * ph[ j - C.size() ] ) % MOD7 + MOD7 ) % MOD7; 
  }
  cout << ans << endl;
  return 0;
}
0