結果

問題 No.430 文字列検索
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2016-09-04 00:01:37
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,573 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 90,832 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-27 15:55:02
合計ジャッジ時間 3,277 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

struct Trie {
  ll t;
  Trie* next[26];
  Trie() : t(0) {for (int i = 0; i < 26; i++) next[i] = (Trie*)0;}
};

Trie *root;

void add(string s){
  Trie *now = root;
  rep(i, 0, s.sz) {
    ll a = s[i] - 'A';
    if (now->next[a] == NULL) {
      now->next[a] = new Trie();
    }
    now = now->next[a];
  }
  now->t += 1;
}

ll f(string s) {
  ll ret = 0;
  Trie *now = root;
  rep(i, 0, s.sz) {
    ll a = s[i] - 'A';
    if (now->next[a] == NULL)break;
    now = now->next[a];
    ret += now->t;
  }
  return ret;
}

// Trie木

int main() {
  string s;
  cin>>s;
  s+="00000000000000000000";
  ll m;
  cin>>m;
  root = new Trie();
  rep(i, 0, m) {
    string s1;
    cin>>s1;
    add(s1);
  }
  ll ans = 0;
  rep(i,0,s.sz-10){
    string s2;
    rep(j,0,10){
      s2 += s[i+j];
    }
    ans += f(s2);
  }
  cout << ans << endl;
  return 0;
}
0