답안 #373261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373261 2021-03-03T23:55:46 Z sam571128 Vlak (COCI20_vlak) C++14
70 / 70
30 ms 20972 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 2e5+5;
int tr[N][26], win[N], p[N][2], cnt = 0;

void insert(string &s, int player){
	int now = 0;
	for(auto c : s){
		p[now][player] = 1;
		if(!tr[now][c-'a']) now = tr[now][c-'a'] = ++cnt;
		else now = tr[now][c-'a'];
	}
	p[now][player] = 1;
}

void dfs(int now, int turn = 1){
	bool has = 0, ok = 0;
	for(int i = 0;i < 26;i++){
		if(!tr[now][i]) continue;
		dfs(tr[now][i],turn^1);
		ok = 1;
		if(win[tr[now][i]]) has = 1;
	}
	if(!ok){
		if(p[now][turn]) win[now] = 1;
	}else if(!has) win[now] = 1;
}

signed main(){
	fastio
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		insert(s,0);
	}
	int m;
	cin >> m;
	for(int i = 0;i < m;i++){
		string s;
		cin >> s;
		insert(s,1);
	}
	dfs(0);
	bool ww = 0;
	for(int i = 0;i < 26;i++){
		if(tr[0][i]){
			ww |= win[tr[0][i]];
		}
	}
	cout << (ww ? "Nina" : "Emilija") << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 19692 KB Output is correct
2 Correct 26 ms 18412 KB Output is correct
3 Correct 26 ms 17644 KB Output is correct
4 Correct 27 ms 19436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 20076 KB Output is correct
2 Correct 30 ms 20972 KB Output is correct
3 Correct 24 ms 19308 KB Output is correct
4 Correct 26 ms 19692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19052 KB Output is correct
2 Correct 25 ms 18556 KB Output is correct
3 Correct 26 ms 19180 KB Output is correct
4 Correct 27 ms 20460 KB Output is correct