Submission #1006562

# Submission time Handle Problem Language Result Execution time Memory
1006562 2024-06-24T03:24:23 Z vjudge1 Vlak (COCI20_vlak) C++17
70 / 70
21 ms 20496 KB
#include<bits/stdc++.h>

using namespace std;

string ans[] = {"Emilija", "Nina"};

struct node
{
  node *ch[26];
  bool f, s;
  bool fw, sw;
  node()
  {
    f = fw = s = sw = false;
    for(int i = 0; i < 26; i++) ch[i] = NULL;
  }

  void insert(string &t, bool fir, int i = 0)
  {
    f |= fir;
    s |= (!fir);
    
    if(i == t.size()) return;
    
    int c = t[i] - 'a';
    if(ch[c] == NULL)
      ch[c] = new node();
    ch[c] -> insert(t, fir, i + 1);
  }

  void compute()
  {
    bool leaf = true;
    for(int i = 0; i < 26; i ++)
      if(ch[i] != NULL)
	{
	  leaf = false;
	  ch[i] -> compute();
	  fw |= !ch[i]->sw;
	  sw |= !ch[i]->fw;
	}

    if(!f) fw = false;
    if(!s) sw = false;
    if(leaf) fw = sw = false;
  }
};

node *root = new node();

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i ++)
    {
      string s;
      cin >> s;
      root -> insert(s, true);
    }
  cin >> n;
  for(int i = 0; i < n; i ++)
    {
      string s;
      cin >> s;
      root -> insert(s, false);
    }
  root -> compute();
  cout << ans[root -> fw] << endl;
  return 0;
}

Compilation message

Main.cpp: In member function 'void node::insert(std::string&, bool, int)':
Main.cpp:23:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if(i == t.size()) return;
      |        ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 19036 KB Output is correct
2 Correct 17 ms 18012 KB Output is correct
3 Correct 19 ms 17080 KB Output is correct
4 Correct 18 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 19708 KB Output is correct
2 Correct 17 ms 20496 KB Output is correct
3 Correct 18 ms 18780 KB Output is correct
4 Correct 17 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 18524 KB Output is correct
2 Correct 16 ms 18116 KB Output is correct
3 Correct 17 ms 18588 KB Output is correct
4 Correct 19 ms 19708 KB Output is correct