-
Notifications
You must be signed in to change notification settings - Fork 1
/
D.cpp
79 lines (65 loc) · 1.42 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll indx = 0;
bool win[2700009], lose[2700009];
struct trie {
trie *nxt[27];
ll num;
trie() {
for(ll i = 0; i < 26; i++)
nxt[i] = nullptr;
num = ++indx;
}
};
trie *start = new trie();
string s;
void add()
{
trie *cur = start;
for(ll i = 0; i < s.length(); i++) {
if(cur -> nxt[s[i] - 'a'] == nullptr)
cur -> nxt[ s[i] - 'a' ] = new trie();
cur = cur -> nxt[s[i] - 'a'];
}
}
void solve(trie *cur)
{
win[cur -> num] = false;
lose[cur -> num] = false;
bool isLeaf = true;
for(ll i = 0; i < 26; i++)
if(cur -> nxt[i] != nullptr) {
solve(cur -> nxt[i]);
isLeaf = false;
win[cur -> num] |= !win[ (cur -> nxt[i]) -> num];
lose[cur -> num] |= !lose[ (cur -> nxt[i]) -> num];
}
if(isLeaf)
lose[cur -> num] = true;
}
int main()
{
std::ios_base::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
for(ll i = 1; i <= n; i++) {
cin >> s;
add();
}
solve(start);
if(win[start -> num]) {
if(k & 1)
cout << "First" << endl;
else {
if(lose[start -> num])
cout << "First" << endl;
else
cout << "Second" << endl;
}
}
else {
cout << "Second" << endl;
}
return 0;
}