Submission #445512

# Submission time Handle Problem Language Result Execution time Memory
445512 2021-07-18T12:22:13 Z grt Vlak (COCI20_vlak) C++17
10 / 70
74 ms 5828 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 = 1e9 + 7, p = 31;
int n, m;
set<int>pl[2];
map<pair<int, bool>, bool>mp;

void rec(int hsh, bool turn) {
	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, 1);
	if(mp[{0, 1}]) cout << "Nina";
	else cout << "Emilija";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 65 ms 5756 KB Output is correct
2 Incorrect 58 ms 5396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 5664 KB Output is correct
2 Incorrect 64 ms 5828 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 5408 KB Output is correct
2 Incorrect 60 ms 5260 KB Output isn't correct
3 Halted 0 ms 0 KB -