Submission #727800

# Submission time Handle Problem Language Result Execution time Memory
727800 2023-04-21T10:57:10 Z madtuber Vlak (COCI20_vlak) C++14
70 / 70
14 ms 10392 KB
#include <bits/stdc++.h>
#define all(x) begin(x),end(x)
#define fir first
#define sec second
#define sz(x) x.size()
#define pb push_back
 
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using pdb = pair<double,double>;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using ull = unsigned long long;
const double EPS = (1e-6);
 
void setio(string s){
    freopen((s + ".in").c_str(),"r",stdin);
    freopen((s + ".out").c_str(),"w",stdout);
}

struct Trie{
    map<char, Trie> c;
    pi own{0,0};
    bool mark = false;

    void insert(int cur, string& s, int pos){
        if (cur % 2) own.sec = 1;
        else own.fir = 1;
        if (pos != sz(s)) c[s[pos]].insert(cur, s, pos+1);
        else mark = true;
    }
    
    //if cur % 2, a's turn, else b's turn
    int dfs(int cur){
        if (cur % 2){
            int res = 0;
            for(auto& j : c){
                if (j.sec.own.sec){
                    res = max(res, j.sec.dfs(cur+1));
                }
            }
            return res;
        }else{
            int res = 1;
            for(auto& j : c){
                if (j.sec.own.fir){
                    res = min(res, j.sec.dfs(cur+1));
                }
            }
            return res;
        }
    }
};

void solve(){
    int n;
    cin >> n;

    Trie tr;

    for(int i{}; i < n; i++){
        string s;
        cin >> s;
        tr.insert(0, s, 0);
    }

    int m;
    cin >> m;

    for(int i{}; i < m; i++){
        string s;
        cin >> s;
        tr.insert(1, s, 0);
    }

    cout << (tr.dfs(0) == 0 ? "Nina" : "Emilija");
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Compilation message

Main.cpp: In member function 'void Trie::insert(int, std::string&, int)':
Main.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         if (pos != sz(s)) c[s[pos]].insert(cur, s, pos+1);
      |                 ^
Main.cpp: In function 'void setio(std::string)':
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s + ".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen((s + ".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 448 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 9812 KB Output is correct
2 Correct 13 ms 9216 KB Output is correct
3 Correct 13 ms 8660 KB Output is correct
4 Correct 14 ms 9556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9940 KB Output is correct
2 Correct 13 ms 10392 KB Output is correct
3 Correct 12 ms 9564 KB Output is correct
4 Correct 13 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9520 KB Output is correct
2 Correct 12 ms 9300 KB Output is correct
3 Correct 14 ms 9524 KB Output is correct
4 Correct 14 ms 10056 KB Output is correct