답안 #707228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707228 2023-03-08T15:39:14 Z Chal1shkan Vlak (COCI20_vlak) C++14
70 / 70
14 ms 21664 KB
# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 2e5 + 25;
const ll inf = 2e9 + 0;
const ll mod = 1e9 + 123;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
 
using namespace std;

struct vertex
{
	int nxt[26];
	int mask;
	vertex ()
	{
		memset(nxt, -1, sizeof nxt);
		mask = 0;
	}
};

int n, m;
vertex t[maxn];
int nv = 1;

void add (string s, int bit)
{
	int v = 0;
	for (int i = 0; i < sz(s); ++i)
	{
		t[v].mask |= (1 << bit);
		int c = s[i] - 'a';
		if (t[v].nxt[c] == -1)
		{
			t[v].nxt[c] = nv++;
		}
		v = t[v].nxt[c];
	}
		t[v].mask |= (1 << bit);
}

bool dfs (int v, int turn)
{
	bool ok = 0;
	for (int c = 0; c < 26; ++c)
	{
		ll to = t[v].nxt[c];
		if (to == -1) continue;
		if (t[to].mask & (1LL << turn) && !dfs(to, turn ^ 1))
		{
			return 1;
		}
	}
	return 0;
}

void ma1n (/* SABR */)
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		add(s, 0);
	}
	cin >> m;
	for (int i = 0; i < m; ++i)
	{
		string s;
		cin >> s;
		add(s, 1);
	}
	cout << (dfs(0, 0) ? "Nina" : "Emilija") << nl;
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << ' ';
        ma1n();
    }
    return 0;
}

Compilation message

Main.cpp: In function 'bool dfs(int, int)':
Main.cpp:56:7: warning: unused variable 'ok' [-Wunused-variable]
   56 |  bool ok = 0;
      |       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 21460 KB Output is correct
2 Correct 9 ms 21456 KB Output is correct
3 Correct 9 ms 21340 KB Output is correct
4 Correct 11 ms 21460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21332 KB Output is correct
2 Correct 13 ms 21432 KB Output is correct
3 Correct 9 ms 21456 KB Output is correct
4 Correct 10 ms 21456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 21368 KB Output is correct
2 Correct 9 ms 21460 KB Output is correct
3 Correct 9 ms 21460 KB Output is correct
4 Correct 11 ms 21388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21460 KB Output is correct
2 Correct 11 ms 21460 KB Output is correct
3 Correct 11 ms 21400 KB Output is correct
4 Correct 11 ms 21464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21600 KB Output is correct
2 Correct 13 ms 21664 KB Output is correct
3 Correct 12 ms 21572 KB Output is correct
4 Correct 12 ms 21588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21600 KB Output is correct
2 Correct 12 ms 21656 KB Output is correct
3 Correct 12 ms 21588 KB Output is correct
4 Correct 12 ms 21600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21664 KB Output is correct
2 Correct 12 ms 21588 KB Output is correct
3 Correct 13 ms 21596 KB Output is correct
4 Correct 14 ms 21572 KB Output is correct