結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
KoshStorm
|
| 提出日時 | 2018-09-24 23:04:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 66 ms / 2,000 ms |
| コード長 | 3,095 bytes |
| コンパイル時間 | 1,691 ms |
| コンパイル使用メモリ | 168,420 KB |
| 実行使用メモリ | 45,568 KB |
| 最終ジャッジ日時 | 2024-11-10 00:20:02 |
| 合計ジャッジ時間 | 2,494 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RREP(i,n) for(long long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl
#define dump(x) cerr << #x << " => " << (x) << endl
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << ends
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m) (!(m.find(n) == m.end()))
#define ENUM(m) for (auto itr = m.begin(); itr != m.end(); ++itr)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> " << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
#define ROUND_PRINT(N,val) cout << fixed;cout << setprecision(N) << val << endl
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define INARR(h,w,x,y) (0 <= y && y < h && 0 <= x && x < w)
#define EQ(a,b) (abs(a - b) < 1e-10)
using namespace std;
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {1,0,-1,0};
constexpr long double pi = M_PI;
constexpr double EPS = 1e-10;
constexpr long MOD = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL,LL> pr;
typedef vector<bool> VB;
typedef vector<pr> VP;
typedef priority_queue<pr,vector<pr>,greater<pr>> pq;
struct Trie {
bool leaf;
Trie* node[256];
Trie(){
leaf = false;
for(int i=0; i<256; i++){
node[i] = (Trie*)0;
}
}
void insert(const string &str){
Trie *r = this;
for(int i=0; i<str.length(); i++){
char c = str[i];
if(!r->node[c]) r->node[c] = new Trie;
r = r->node[c];
}
r->leaf = true;
}
int find(const string &str) const {
const Trie *r = this;
int cnt = 0;
for(int i=0; i<str.length(); i++){
char c = str[i];
if(!r->node[c]) return cnt;
r = r->node[c];
if ((r->leaf) == 1) {
++cnt;
}
}
return cnt;
}
};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
long M;
string S,C;
cin >> S >> M;
Trie tree;
REP(i,M) {
cin >> C;
tree.insert(C);
}
string s = S;
LL cnt = 0;
while (s.size() > 0) {
cnt += tree.find(s);
s = s.substr(1);
}
cout << cnt << endl;
}
KoshStorm