結果

問題 No.430 文字列検索
ユーザー yaoshimaxyaoshimax
提出日時 2016-10-03 09:28:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 745 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 58,424 KB
実行使用メモリ 7,704 KB
最終ジャッジ日時 2023-08-13 18:36:36
合計ジャッジ時間 3,805 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
   string S;
   cin >> S;
   int M;
   cin >> M;
   int ans = 0;
   int len = S.size();
   for( int i = 0 ; i < M; i++){
      string C;
      cin >> C;
      int size=C.size();
      long long hash=0;
      long long offset=1LL;
      for( int j = 0 ; j < size; j++ ){
         hash*=26;
         hash+=C[j]-'A';
         offset*=26;
      }
      long long curHash=0;
      for( int j =0; j+1 <size; j++ ){
         curHash*=26;
         curHash+=S[j]-'A';
      }
      for( int j=size-1; j<len; j++){
         curHash*=26;
         curHash+=S[j]-'A';
         curHash%=offset;
         if( curHash==hash ) ans++;
      }
   }
   cout << ans << endl;
}
0