Submission #531319

# Submission time Handle Problem Language Result Execution time Memory
531319 2022-02-28T11:57:51 Z fcw Vlak (COCI20_vlak) C++17
70 / 70
19 ms 21928 KB
#include <bits/stdc++.h>
#define st first
#define nd second
using lint = int64_t;
constexpr int mod = int(1e9) + 7;
constexpr int inf = 0x3f3f3f3f;
constexpr int ninf = 0xcfcfcfcf;
constexpr lint linf = 0x3f3f3f3f3f3f3f3f;
const long double pi = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
	return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;

int trie[200100][26];
int flag[200100];
bool w[200100];

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	memset(trie, -1, sizeof trie);
	int n, m;
	cin>>n;
	vector<string>a(n);
	int sz = 1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		int cur = 0;
		for(char c : a[i]){
			if(trie[cur][c-'a'] == -1){
				trie[cur][c-'a'] = sz++;
			}
			cur = trie[cur][c-'a'];
			flag[cur] |= 1;
		}
	}
	cin>>m;
	vector<string>b(m);
	for(int i=0;i<m;i++){
		cin>>b[i];
		int cur = 0;
		for(char c : b[i]){
			if(trie[cur][c-'a'] == -1){
				trie[cur][c-'a'] = sz++;
			}
			cur = trie[cur][c-'a'];
			flag[cur] |= 2;
		}
	}
	auto dfs = [&](auto& self, int cur, int num) -> bool{
		bool ok = 0;
		for(int i=0;i<26;i++){
			if(trie[cur][i] == -1) continue;
			if(num&1){
				if(flag[trie[cur][i]] == 2) ok = 1;
				else if(flag[trie[cur][i]] == 3) ok |= !self(self, trie[cur][i], num+1);
			}
			else{
				if(flag[trie[cur][i]] == 1) ok = 1;
				else if(flag[trie[cur][i]] == 3) ok |= !self(self, trie[cur][i], num+1);
			}
		}
		return w[cur] = ok;
	};
	dfs(dfs, 0, 0);
	if(w[0]) cout<<"Nina\n";
	else cout<<"Emilija\n";

	return 0;
}
/*
[  ]Leu o problema certo???
[  ]Ver se precisa de long long
[  ]Viu o limite dos fors (é n? é m?)
[  ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[  ]Testar sample
[  ]Testar casos de  borda
[  ]1LL no 1LL << i
[  ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# Verdict Execution time Memory Grader output
1 Correct 9 ms 20684 KB Output is correct
2 Correct 9 ms 20684 KB Output is correct
3 Correct 9 ms 20684 KB Output is correct
4 Correct 9 ms 20664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20592 KB Output is correct
2 Correct 9 ms 20688 KB Output is correct
3 Correct 9 ms 20684 KB Output is correct
4 Correct 8 ms 20672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20668 KB Output is correct
2 Correct 8 ms 20684 KB Output is correct
3 Correct 8 ms 20684 KB Output is correct
4 Correct 8 ms 20684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20684 KB Output is correct
2 Correct 10 ms 20684 KB Output is correct
3 Correct 8 ms 20684 KB Output is correct
4 Correct 8 ms 20684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 21708 KB Output is correct
2 Correct 14 ms 21708 KB Output is correct
3 Correct 16 ms 21808 KB Output is correct
4 Correct 19 ms 21928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21324 KB Output is correct
2 Correct 13 ms 21532 KB Output is correct
3 Correct 13 ms 21564 KB Output is correct
4 Correct 12 ms 21584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 21548 KB Output is correct
2 Correct 15 ms 21700 KB Output is correct
3 Correct 15 ms 21700 KB Output is correct
4 Correct 14 ms 21716 KB Output is correct