답안 #1089794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089794 2024-09-17T07:09:59 Z SalihSahin Vlak (COCI20_vlak) C++14
70 / 70
25 ms 30656 KB
#include<bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int mod = 1e9 + 7;
const int inf = 1e9;
const int N = 2048;

struct node{
  int nxt[26];
  node(){
    for(int i = 0; i < 26; i++){
      nxt[i] = -1;
    }
  }
};

struct Trie{
  vector<node> trie;

  void start(){
    trie.pb(node());
  }

  void add(int ind, string s){
    for(int i = 0; i < s.size(); i++){
      if(trie[ind].nxt[s[i] - 'a'] == -1){
        trie[ind].nxt[s[i] - 'a'] = trie.size();
        trie.pb(node());
      }

      ind = trie[ind].nxt[s[i] - 'a'];
    }
  }
};

Trie tr1, tr2;

int dp(int ind1, int ind2, int turn){
  if(turn){
    bool win = 0;
    for(int i = 0; i < 26; i++){
      if(tr1.trie[ind1].nxt[i] == -1) continue;
      if(tr1.trie[ind1].nxt[i] != -1 && tr2.trie[ind2].nxt[i] == -1) win = 1;
      else win |= (!dp(tr1.trie[ind1].nxt[i], tr2.trie[ind2].nxt[i], (turn^1)));
    }
    return win;
  }
  else{
    bool win = 0;
    for(int i = 0; i < 26; i++){
      if(tr2.trie[ind2].nxt[i] == -1) continue;
      if(tr2.trie[ind2].nxt[i] != -1 && tr1.trie[ind1].nxt[i] == -1) win = 1;
      else win |= (!dp(tr1.trie[ind1].nxt[i], tr2.trie[ind2].nxt[i], (turn^1)));
    }
    return win;
  }
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int n;
  cin>>n;
  tr1.start();
  for(int i = 0; i < n; i++){
    string s;
    cin>>s;

    tr1.add(0, s);
  }

  int m;
  cin>>m;
  tr2.start();
  for(int i = 0; i < m; i++){
    string s;
    cin>>s;

    tr2.add(0, s);
  }

  int ans = dp(0, 0, 1);
  if(ans) cout<<"Nina"<<endl;
  else cout<<"Emilija"<<endl;
  return 0;
}

Compilation message

Main.cpp: In member function 'void Trie::add(long long int, std::string)':
Main.cpp:27:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 784 KB Output is correct
2 Correct 0 ms 780 KB Output is correct
3 Correct 1 ms 780 KB Output is correct
4 Correct 0 ms 884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 784 KB Output is correct
2 Correct 1 ms 888 KB Output is correct
3 Correct 1 ms 784 KB Output is correct
4 Correct 1 ms 1136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 784 KB Output is correct
2 Correct 1 ms 780 KB Output is correct
3 Correct 1 ms 776 KB Output is correct
4 Correct 1 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 776 KB Output is correct
2 Correct 1 ms 780 KB Output is correct
3 Correct 1 ms 784 KB Output is correct
4 Correct 1 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 30280 KB Output is correct
2 Correct 22 ms 29636 KB Output is correct
3 Correct 25 ms 29336 KB Output is correct
4 Correct 21 ms 29896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 30408 KB Output is correct
2 Correct 20 ms 30656 KB Output is correct
3 Correct 19 ms 29888 KB Output is correct
4 Correct 21 ms 30148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 29892 KB Output is correct
2 Correct 19 ms 29712 KB Output is correct
3 Correct 18 ms 29892 KB Output is correct
4 Correct 23 ms 30404 KB Output is correct