Submission #920437

# Submission time Handle Problem Language Result Execution time Memory
920437 2024-02-02T14:39:53 Z BBart888 Vlak (COCI20_vlak) C++14
70 / 70
10 ms 10328 KB
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <climits>
#include <functional>
#include <cstdlib>
#include <complex>
#include <array>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <random>
#define fileIO(name) if(fopen(name".in", "r")) {freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);}



using namespace std;
const int MAXN = 1e6 + 111;
using ll = long long;
const int P = 31;
const ll mod1 = 1e9 + 7;
const ll mod2 = 998244353;
using ld = long double;
const ld EPS = 1e-5;
using pii = pair<int, int>;
typedef complex<ll> Point;
const int K = 600;


int n, m;
int node_cnt;
int trie[MAXN][27];
bool type[MAXN][2];


void add(const string & str, int mode)
{
	int curr_node=  0;
	for (int i = 0; i < str.size(); i++)
	{
		int nxt = str[i] - 'a';
		if (trie[curr_node][nxt] == 0)
			trie[curr_node][nxt] = ++node_cnt;
		curr_node = trie[curr_node][nxt];
		type[curr_node][mode] = true;
	}
}



int dfs(int v,int len)
{
	int turn = len & 1;
	//cout << turn << " " << v << " " << len << '\n';
	if (type[v][0] && !type[v][1])
		return 1;
	if (!type[v][0] && type[v][1])
		return 0;

	int ch_cnt = 0;
	for (int i = 0; i < 27; i++)
		if (trie[v][i] > 0)
			ch_cnt++;

	if (ch_cnt == 0)
	{
		if (len % 2)
			return 1;
		else
			return 0;
	}
	int cnt_opti = 0;
	if (turn == 0)
	{
		for (int i = 0; i < 27; i++)
		{
			int nxt = trie[v][i];
			if (nxt > 0)
			{
				cnt_opti += (dfs(nxt, len + 1) == 1);
			}
		}
		if (cnt_opti > 0)
			return 1;
		else
			return 0;
	}
	else
	{
		for (int i = 0; i < 27; i++)
		{
			int nxt = trie[v][i];
			if (nxt > 0)
			{
				cnt_opti += (dfs(nxt, len + 1) == 0);
			}
		}
		if (cnt_opti > 0)
			return 0;
		else
			return 1;
	}
}



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	//fileIO("cardgame");

	

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		add(str, 0);
	}
	
	cin >> m;

	for (int i = 0; i < m; i++)
	{
		string str;
		cin >> str;
		add(str, 1);
	}

	if (dfs(0, 0))
		cout << "Nina\n";
	else
		cout << "Emilija\n";


	


	return 0;
}







Compilation message

Main.cpp: In function 'void add(const string&, int)':
Main.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for (int i = 0; i < str.size(); i++)
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9816 KB Output is correct
2 Correct 8 ms 9048 KB Output is correct
3 Correct 7 ms 8624 KB Output is correct
4 Correct 8 ms 9560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9816 KB Output is correct
2 Correct 8 ms 10328 KB Output is correct
3 Correct 7 ms 9564 KB Output is correct
4 Correct 7 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9304 KB Output is correct
2 Correct 10 ms 9168 KB Output is correct
3 Correct 7 ms 9308 KB Output is correct
4 Correct 8 ms 10072 KB Output is correct