이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define mod 998244353
#define ll long long
int numbr = 0;
class Node{
public:
unordered_map<char, Node*> childs;
vector<int> col;
int num = 0;
Node(int nu){
num = nu;
col.assign(2, 0);
}
};
Node* create(){
Node* node = new Node(numbr);
numbr++;
return node;
}
void add(Node* root, string s, int co){
Node* curr = root;
for (auto v : s){
if (curr->childs.find(v) == curr->childs.end()){
curr->childs[v] = create();
}
curr = curr->childs[v];
curr->col[co] = 1;
}
}
vector<int> dp(numbr + 1, 2);
void dfs(Node* curr, int turn){
dp[curr->num] = 1 - turn;
int am = 0, an = 0;
for (auto el : curr->childs){
if (el.second->col[turn] == 1){
am++;
dfs(el.second, 1 - turn);
}
else{
an++;
}
if ((dp[el.second->num] == turn) && el.second->col[turn] == 1){
dp[curr->num] = turn;
}
}
/*if (am == 0 && an == 0){
dp[curr->num] = turn;
}*/
}
int main(){
int n, m;
string s;
Node* root = create();
cin>>n;
for (int i = 0; i < n; i++){
cin>>s;
add(root, s, 0);
}
cin>>m;
for (int i = 0; i < m; i++){
cin>>s;
add(root, s, 1);
}
dp.assign(numbr + 1, 2);
dfs(root, 0);
if (dp[0] == 0){
cout<<"Nina";
}
else{
cout<<"Emilija";
}
}
# | 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... |