結果

問題 No.430 文字列検索
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2016-09-04 00:15:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,593 bytes
コンパイル時間 727 ms
コンパイル使用メモリ 90,000 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-05-03 04:14:53
合計ジャッジ時間 1,544 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 11 ms
7,936 KB
testcase_02 AC 7 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 12 ms
6,528 KB
testcase_12 AC 13 ms
7,040 KB
testcase_13 AC 13 ms
7,040 KB
testcase_14 AC 10 ms
6,144 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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] = NULL;}
};

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) {
    if(s[i]=='0')break;
    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-15){
    string s2;
    rep(j,0,10){
      s2 += s[i+j];
    }
    ans += f(s2);
  }
  cout << ans << endl;
  return 0;
}
0