結果

問題 No.430 文字列検索
ユーザー yaoshimaxyaoshimax
提出日時 2016-10-03 09:36:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 69,148 KB
実行使用メモリ 26,404 KB
最終ジャッジ日時 2023-08-15 17:34:29
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 160 ms
26,404 KB
testcase_02 AC 7 ms
4,376 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 161 ms
26,148 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 10 ms
5,640 KB
testcase_11 AC 64 ms
7,500 KB
testcase_12 AC 64 ms
7,444 KB
testcase_13 AC 67 ms
7,396 KB
testcase_14 AC 49 ms
5,800 KB
testcase_15 AC 39 ms
5,224 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 9 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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