답안 #488722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488722 2021-11-20T07:54:00 Z JerryLiu06 Vlak (COCI20_vlak) C++17
70 / 70
11 ms 9804 KB
// https://oj.uz/problem/view/COCI20_vlak

#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using db = double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0);
#define FASTIOF ios_base::sync_with_stdio(false); fin.tie(0);

#define mp make_pair
#define f first
#define s second
 
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert 
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
 
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); }
 
const int MOD = 1e9 + 7;
const int MX = 2e5 + 10;
const ll INF = 1e18;

template<int SZ> struct Trie {
    int trie[SZ][26], num = 1; bool fst[SZ], sec[SZ];

    void insert(str S, int t) {
        int curNode = 1;
        
        F0R(i, sz(S)) {
            if (!trie[curNode][S[i] - 'a']) {
                trie[curNode][S[i] - 'a'] = ++num;
            }
            curNode = trie[curNode][S[i] - 'a'];
            
            if (!t) {
                fst[curNode] = true;
            }
            else {
                sec[curNode] = true;
            }
        }
    }
    bool DFS(int X, int move) {
        F0R(i, 26) {
            if (!trie[X][i]) continue;

            if ((move == 0 && !fst[trie[X][i]]) || (move == 1 && !sec[trie[X][i]])) {
                continue;
            }
            if (!DFS(trie[X][i], 1 - move)) {
                return true;
            }
        }
        return false;
    }
};
int N, M; Trie<MX> T;

int main() {
    FASTIO;

    cin >> N;

    F0R(i, N) {
        str S; cin >> S;

        T.insert(S, 0);
    }
    cin >> M;

    F0R(i, M) {
        str S; cin >> S;

        T.insert(S, 1);
    }
    if (T.DFS(1, 0)) {
        cout << "Nina" << "\n";
    }
    else {
        cout << "Emilija" << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9324 KB Output is correct
2 Correct 11 ms 8624 KB Output is correct
3 Correct 9 ms 8268 KB Output is correct
4 Correct 9 ms 9036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9420 KB Output is correct
2 Correct 8 ms 9804 KB Output is correct
3 Correct 8 ms 9152 KB Output is correct
4 Correct 8 ms 9284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8908 KB Output is correct
2 Correct 8 ms 8780 KB Output is correct
3 Correct 9 ms 8920 KB Output is correct
4 Correct 9 ms 9548 KB Output is correct