답안 #474072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474072 2021-09-16T18:53:10 Z mychecksedad Vlak (COCI20_vlak) C++17
20 / 70
90 ms 169244 KB
#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

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++){
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 168476 KB Output is correct
2 Correct 77 ms 168540 KB Output is correct
3 Correct 77 ms 168584 KB Output is correct
4 Correct 82 ms 168524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 168516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 168536 KB Output is correct
2 Correct 79 ms 168584 KB Output is correct
3 Incorrect 77 ms 168572 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 80 ms 168584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 168924 KB Output is correct
2 Incorrect 84 ms 169108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 168804 KB Output is correct
2 Correct 85 ms 168744 KB Output is correct
3 Correct 83 ms 168812 KB Output is correct
4 Correct 81 ms 168732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 168880 KB Output is correct
2 Correct 83 ms 168796 KB Output is correct
3 Correct 87 ms 168812 KB Output is correct
4 Incorrect 83 ms 169244 KB Output isn't correct