Submission #445515

# Submission time Handle Problem Language Result Execution time Memory
445515 2021-07-18T12:33:58 Z grt Vlak (COCI20_vlak) C++17
70 / 70
73 ms 5780 KB
#include <bits/stdc++.h>
#define ST first
#define ND second
#define PB push_back

using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int mod = 1012414159, p = 317;
int n, m;
set<int>pl[2];
map<pair<int, bool>, bool>mp;

void rec(int hsh, bool turn) {
	if(mp.count({hsh,turn})) return;
	bool win = false;
	for(int i = 1; i <= 26; ++i) {
		int h2 = ((ll)hsh * p + i) % mod;
		if(pl[turn].count(h2)) {
			if(!mp.count({h2, turn ^ 1})) rec(h2, turn ^ 1);
			if(!mp[{h2, turn ^ 1}]) win = true;
		}
	}
	mp[{hsh, turn}] = win;
}


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		int hsh = 0;
		for(auto c : s) {
			hsh = ((ll)hsh * p + (c - 'a' + 1)) % mod;
			pl[0].insert(hsh);
		}
	}
	cin >> m;
	for(int i = 0; i < m; ++i) {
		string s;
		cin >> s;
		int hsh = 0;
		for(auto c : s) {
			hsh = ((ll)hsh * p + (c - 'a' + 1)) % mod;
			pl[1].insert(hsh);
		}
	}
	rec(0, 0);
	if(mp[{0, 0}]) cout << "Nina";
	else cout << "Emilija";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 5480 KB Output is correct
2 Correct 65 ms 5156 KB Output is correct
3 Correct 59 ms 5156 KB Output is correct
4 Correct 63 ms 5528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 5448 KB Output is correct
2 Correct 64 ms 5652 KB Output is correct
3 Correct 63 ms 5540 KB Output is correct
4 Correct 64 ms 5480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 5192 KB Output is correct
2 Correct 62 ms 5060 KB Output is correct
3 Correct 61 ms 5380 KB Output is correct
4 Correct 73 ms 5780 KB Output is correct