結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
CELICA
|
| 提出日時 | 2020-11-03 08:30:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 1,119 bytes |
| コンパイル時間 | 1,374 ms |
| コンパイル使用メモリ | 172,308 KB |
| 実行使用メモリ | 8,544 KB |
| 最終ジャッジ日時 | 2024-11-10 00:48:33 |
| 合計ジャッジ時間 | 1,971 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
class Trie
{
public:
int value;
array<Trie*, 26> next;
Trie() : value(0)
{
next.fill(nullptr);
}
void insert(const string s)
{
if (s[0] == '\0')
{
++this->value;
return;
}
if (this->next[s[0] - BASE] == nullptr)
this->next[s[0] - BASE] = new Trie();
this->next[s[0] - BASE]->insert(s.substr(1));
}
bool find(const string s, int& count)
{
int countw{ count };
for (auto it = s.begin(); it != s.end(); ++it)
{
Trie* cur = this;
auto its = it;
while (its != s.end() && cur)
{
cur = cur->next[*its - BASE];
if (cur)
count += cur->value;
++its;
}
}
return countw > count;
}
private:
const char BASE{ 'A' };
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
string S;
cin >> S;
int M;
cin >> M;
vector<string> C(M);
for (auto&& it : C)
cin >> it;
Trie* root = new Trie();
for (const auto& it : C)
root->insert(it);
int cnt{ 0 };
root->find(S, cnt);
cout << cnt << "\n";
return 0;
}
CELICA