# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1083525 | HaciyevAlik | Vlak (COCI20_vlak) | C++14 | 21 ms | 27740 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define oo 1000000000000000
const int mx = 1e6 + 5;
int trie[mx][26];
int last;
int dp[mx];
vector<int> mark;
void insert(string s,bool turn) {
int cur = 0;
for(int i = 0; i < s.size(); ++i) {
if(!trie[cur][s[i]-'a']) {
trie[cur][s[i]-'a'] = ++last;
}
cur = trie[cur][s[i]-'a'];
}
if(mark[cur] == -1) {
mark[cur] = turn;
} else {
mark[cur] = (mark[cur] != turn ? 2 : mark[cur]);
}
}
void dfs(int u,int lvl) {
if(lvl % 2) {
dp[u] = 1;
} else {
dp[u] = 2;
}
bool check = false;
for(int i = 0; i < 26; ++i) {
if(trie[u][i]) {
dfs(trie[u][i],lvl + 1);
check = 1;
if(lvl%2) dp[u] = max(dp[u],dp[trie[u][i]]);
else dp[u] = min(dp[u],dp[trie[u][i]]);
}
}
if(!check) {
if(mark[u] == 2) {
if(lvl%2) dp[u] = 1;
else dp[u] = 2;
} else {
dp[u] = mark[u] + 1;
}
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
mark.assign(mx, -1);
int n; cin >> n;
for(int i = 1; i <= n; ++i) {
string s; cin >> s;
insert(s,0);
}
int m; cin >> m;
for(int i = 1; i <= m; ++i) {
string s; cin >> s;
insert(s,1);
}
dfs(0,0);
if(dp[0] == 1) {
cout << "Nina";
} else {
cout << "Emilija";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |