# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
692235 |
2023-02-01T08:37:22 Z |
tamthegod |
Vlak (COCI20_vlak) |
C++17 |
|
64 ms |
96456 KB |
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, m;
string s[maxN], t[maxN];
void ReadInput()
{
cin >> n;
for(int i=1; i<=n; i++)
cin >> s[i];
cin >> m;
for(int i=1; i<=m; i++)
cin >> t[i];
}
struct Trie
{
struct TNode
{
int id;
int type;
int child[30];
};
vector<TNode> tree;
void new_node()
{
TNode tmp;
tmp.id = tree.size();
tmp.type = 0;
for(int i=0; i<30; i++)
tmp.child[i] = -1;
tree.pb(tmp);
}
void add(string s, int type)
{
int id = 0;
for(char c : s)
{
int w = c - 'a';
if(tree[id].child[w] == -1)
{
new_node();
tree[id].child[w] = tree.size() - 1;
}
id = tree[id].child[w];
tree[id].type |= type;
}
tree[id].type = type;
}
bool get(int id, int turn)
{
if(!(turn & 1))
{
bool ok = false;
for(int w=0; w<27; w++)
{
if(tree[id].child[w] != -1 && tree[tree[id].child[w]].type >= 2)
{
ok |= get(tree[id].child[w], turn ^ 1);
}
}
if(id == 5)
{
// cout << ok;exit(0);
}
return ok;
}
else
{
bool ok = true;
for(int w=0; w<27; w++)
{
if(tree[id].child[w] != -1 && tree[tree[id].child[w]].type != 2)
{
ok &= get(tree[id].child[w], turn ^ 1);
}
}
if(id == 4)
{
//cout << ok;exit(0);
}
return ok;
}
}
};
void Solve()
{
Trie trie;
trie.new_node();
for(int i=1; i<=n; i++)
trie.add(s[i], 1);
for(int i=1; i<=m; i++)
trie.add(t[i], 2);
// cout << trie.tree[5].type;exit(0);
// cout << trie.tree[4].child[1];return;
// cout << trie.tree[4].type;return;
cout << (trie.get(0, 0) ? "Quan" : "Nguyen");
}
int32_t main()
{
// freopen("CONC.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
63580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
63616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
63240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
63308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
96456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
96356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
96428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |