結果
| 問題 |
No.2102 [Cherry Alpha *] Conditional Reflection
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-12 05:13:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 948 ms / 3,000 ms |
| コード長 | 1,666 bytes |
| コンパイル時間 | 1,167 ms |
| コンパイル使用メモリ | 81,384 KB |
| 最終ジャッジ日時 | 2025-02-09 10:01:56 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 70 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
struct Trie
{
int c;
std::vector<std::vector<int>> v;
Trie(int c) : c(c), v(1)
{
v[0].resize(c);
}
void insert(string &s)
{
int u = 0;
int n = s.size();
for(int i = 0; i < n; i++)
{
if(!v[u][s[i] - 'a'])
{
v[u][s[i] - 'a'] = v.size();
std::vector<int> w(c);
v.push_back(w);
}
u = v[u][s[i] - 'a'];
}
}
bool find_sub(int i, int u, int n, bool swaped, string &s)
{
if(i == n)
{
return true;
}
bool res = false;
if(v[u][s[i] - 'a'])
{
res |= find_sub(i + 1, v[u][s[i] - 'a'], n, swaped, s);
}
if(i < n - 1 && !swaped && s[i] != s[i + 1] && v[u][s[i + 1] - 'a'])
{
int r = v[u][s[i + 1] - 'a'];
if(v[r][s[i] - 'a'])
{
res |= find_sub(i + 2, v[r][s[i] - 'a'], n, true, s);
}
}
return res;
}
bool find(string &s)
{
int n = s.size();
return find_sub(0, 0, n, false, s);
}
};
int main()
{
int n;
cin >> n;
vector<Trie> tr(10000, Trie(26));
int d[1000005];
for(int i = 0; i <= 1000000; i++)
{
d[i] = -1;
}
int k = 0;
for(int i = 0; i < n; i++)
{
string s;
cin >> s;
int l = s.size();
if(d[l] == -1)
{
d[l] = k++;
}
cout << (tr[d[l]].find(s) ? "Yes" : "No") << endl;
tr[d[l]].insert(s);
}
}