結果

問題 No.430 文字列検索
ユーザー char134217728char134217728
提出日時 2017-08-17 23:28:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 165,696 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 14:54:50
合計ジャッジ時間 2,483 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 66 ms
5,376 KB
testcase_02 AC 30 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 15 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 38 ms
5,376 KB
testcase_12 AC 37 ms
5,376 KB
testcase_13 AC 37 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 24 ms
5,376 KB
testcase_17 AC 22 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:21:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
   21 | main(){
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll mod1 = 1e9+7;
const ll mod2 = 999999937;

int m;
ll mod[2] = {mod1, mod2};
set<pll> sl;
int il[50020];
pll h[11];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s >> m;
  FOR(i, 0, m){
    string c;
    cin >> c;
    ll d[2] = {0, 0};
    FOR(i, 0, c.size()){
      int k = (c[i] - 'A') + 1;
      FOR(j, 0, 2){
        d[j] = (d[j] * 28 + k) % mod[j];
      }
    }
    sl.insert(pll(d[0], d[1]));
  }
  FOR(i, 0, 9){
    il[i] = 27;
  }
  FOR(i, 9, s.size() + 9){
    il[i] = (s[i - 9] - 'A') + 1;
  }
  ll ans = 0;
  FOR(i, 0, s.size() + 9){
    FORR(j, 10, 1){
      h[j].first  = (h[j-1].first  * 28 + il[i]) % mod[0];
      h[j].second = (h[j-1].second * 28 + il[i]) % mod[1];
      if(sl.find(h[j]) != sl.end()) ans++;
    }
  }
  cout << ans << endl;
}
0