結果

問題 No.430 文字列検索
ユーザー yaoshimax
提出日時 2016-10-03 09:36:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 70,036 KB
実行使用メモリ 26,496 KB
最終ジャッジ日時 2024-11-10 00:08:07
合計ジャッジ時間 1,746 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
int main(){
   string S;
   cin >> S;
   int M;
   cin >> M;
   int ans = 0;
   int len = S.size();
   map<long long, int> cnt;
   for( int i = 0 ; i < len; i++){
      long long hash = 0;
      for( int j = 0; j < 10 && i+j <len; j++){
        hash*=27;
        hash+=S[i+j]-'A'+1;
        cnt[hash]++;
      }
   }
   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*=27;
         hash+=C[j]-'A'+1;
         offset*=27;
      }
      ans+=cnt[hash];
   }
   cout << ans << endl;
}
0