Submission #474072

#TimeUsernameProblemLanguageResultExecution timeMemory
474072mychecksedadVlak (COCI20_vlak)C++17
20 / 70
90 ms169244 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int N = 1000000, F = 1e9;

struct Node{
	int child[26];
	short value, color;
	Node(){
		for(int i = 0; i < 26; i++) child[i] = -1;
		value = color = 0;
	}
	
};


int n, m, cur = 1;
Node trie[N];
string s[N], t[N];
bool dfs(int v, int d){
	if(v == 0){
		int ans = 0;
		for(int i = 0; i < 26; i++) if(trie[v].child[i] != -1) ans |= dfs(trie[v].child[i], d+1);
		return ans;
	}
	if(d & 1){
		if(trie[v].color == 1){
			return 1;
		}else if(trie[v].color == 3){
			return 1;
		}else if(trie[v].value == 1){
			return 1;
		}else if(!(trie[v].value & 1)){
			return 0;
		}else{
			bool ans = 0;
			for(int i = 0; i < 26; i++){
				if(trie[v].child[i] != -1) ans |= dfs(trie[v].child[i], d+1);
			}
			return ans;
		}
	}
	if(trie[v].color == 2){
		return 0;
	}else if(trie[v].color == 3){
		return 0;
	}else if(trie[v].value == 2){
		return 0;
	}else if(!(trie[v].value & 2)){
		return 1;
	}else{
		bool ans = 1;
		for(int i = 0; i < 26; i++){
			if(trie[v].child[i] != -1) ans &= dfs(trie[v].child[i], d+1);
		}
		return ans;
	}
}

int main(){
	cin.tie(0); ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		int v = 0;
		for(int j = 0; j < s[i].length(); j++){
			if(trie[v].child[s[i][j] - 'a'] == -1){
				trie[v].child[s[i][j] - 'a'] = cur++;
			}
			v = trie[v].child[s[i][j] - 'a'];
			trie[v].value += 1; 
		}
		trie[v].color += 1;
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> t[i];
		int v = 0;
		for(int j = 0; j < t[i].length(); j++){
			if(trie[v].child[t[i][j] - 'a'] == -1){
				trie[v].child[t[i][j] - 'a'] = cur++;
			}
			v = trie[v].child[t[i][j] - 'a'];
			trie[v].value += 2;
		}
		trie[v].color += 2;
	}
	bool ans = dfs(0, 0);
	if(ans == 0) cout << "Emilija";
	else cout << "Nina";



	return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for(int j = 0; j < s[i].length(); j++){
      |                  ~~^~~~~~~~~~~~~~~
Main.cpp:80:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |   for(int j = 0; j < t[i].length(); j++){
      |                  ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...