結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2020-07-12 14:51:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 1,151 bytes |
| コンパイル時間 | 2,044 ms |
| コンパイル使用メモリ | 205,300 KB |
| 最終ジャッジ日時 | 2025-01-11 20:00:08 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000
struct trie{
struct node{
vector<int> next;
int str=-1;
node(int k){
next.resize(k,-1);
}
};
vector<node> _N;
vector<string> _S;
int n;
trie(int k){
n = k;
_N.push_back(node(n));
}
void add(string s){
int now = 0;
for(int i=0;i<s.size();i++){
int c = get(s[i]);
if(_N[now].next[c]==-1){
_N[now].next[c] = _N.size();
_N.push_back(node(n));
}
now = _N[now].next[c];
}
_N[now].str = _S.size();
_S.push_back(s);
}
int check(string s){
int now = 0;
for(int i=0;i<s.size();i++){
int c = get(s[i]);
if(_N[now].next[c]==-1)return -1;
now = _N[now].next[c];
}
return _N[now].str;
}
int get(char c){
return c-'A';
}
};
int main(){
string S;
cin>>S;
int M;
cin>>M;
trie T(26);
for(int i=0;i<M;i++){
string s;
cin>>s;
T.add(s);
}
int ans = 0;
for(int i=1;i<=10;i++){
for(int j=0;j+i<=S.size();j++){
int ret = T.check(S.substr(j,i));
if(ret!=-1)ans++;
}
}
cout<<ans<<endl;
return 0;
}
沙耶花