답안 #1108919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108919 2024-11-05T16:46:11 Z themaver1cks Vlak (COCI20_vlak) C++14
20 / 70
27 ms 24668 KB
/**
。∠(*・ω・)っ  ⌒ 由 ~    (( ,,・з・,, ))
 _Π_____。
/______/~\
| 田田|門|
> love miku so muchhhh <3
**/
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define el "\n"

typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
// var dec
int n, m;
// ds dec

//
struct Trie
{
    struct Node
    {
        Node* child[26];
        vector <int> color;

        Node()
        {
            for (int i=0; i<26; ++i) child[i] = NULL;
            color.resize(2, 0);
        }
    };

    Node* root;
    int cur;
    Trie(): cur(0)
    {
        root = new Node();
    }
    //
    void add_string(string s, bool is_blue)
    {
        Node* p = root;
        for (auto x: s)
        {
            int c = x-'a';
            if (p->child[c] == NULL) p->child[c] = new Node();

            p = p->child[c];
            p->color[is_blue]++;
        }
    }
    //
    bool calc(Node* p, bool is_blue)
    {
        bool no_child = 1, win = 0;
        for (int c=0; c<26; ++c)
        {
            if (p->child[c] != NULL) no_child = 0;
            if (p->child[c] != NULL && p->child[c]->color[is_blue] != 0)
            {
//                cout << c << el;
//                if (is_blue) win |= calc(p->child[c], is_blue^1);
//                else win |= !(calc(p->child[c], is_blue^1));
                win |= !(calc(p->child[c], is_blue^1));
            }
        }
//        cout << no_child << " " << win << " " << is_blue << el;
        if (no_child && p->color[is_blue]) return is_blue;
        if (win) return is_blue;
        else return !is_blue;
    }
    //
    bool call_func()
    {
        Node* p = root;
        bool win = 0;
        for (int c=0; c<26; ++c)
        {
            if (p->child[c] != NULL && p->child[c]->color[1] > 0)
            {
                bool temp = calc(p->child[c], 0);
//                cout << c << " " << temp << el << el;
                win |= temp;
            }
        }
        return win;
    }
} trie;
//
void solve()
{
    cin >> n;
    for (int i=1; i<=n; ++i)
    {
        string s; cin >> s;
        trie.add_string(s, 1);
    }
    cin >> m;
    for (int i=1; i<=m; ++i)
    {
        string s; cin >> s;
        trie.add_string(s, 0);
    }
    cout << (trie.call_func() ? "Nina" : "Emilija") << el;
}
//
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("lmao.inp", "r"))
    {
        freopen("lmao.inp", "r", stdin);
        freopen("lmao.out", "w", stdout);
    }
    int t = 1;
//    cin >> t;
    while (t--) solve();
    return 0;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |         freopen("lmao.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         freopen("lmao.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Incorrect 1 ms 592 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Incorrect 1 ms 592 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 23112 KB Output is correct
2 Incorrect 26 ms 21584 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23676 KB Output is correct
2 Correct 23 ms 24668 KB Output is correct
3 Correct 22 ms 22648 KB Output is correct
4 Correct 22 ms 23132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 22420 KB Output is correct
2 Incorrect 23 ms 21840 KB Output isn't correct
3 Halted 0 ms 0 KB -