Submission #703579

#TimeUsernameProblemLanguageResultExecution timeMemory
703579PoonYaPatVlak (COCI20_vlak)C++14
70 / 70
20 ms21880 KiB
#include <bits/stdc++.h> using namespace std; struct node { char c; int depth; bool k1,k2,win,endword; node *child[26]; }; struct node *getnode(char c, int depth) { struct node *pnode=new node; pnode->c=c; pnode->depth=depth; pnode->k1=false; pnode->k2=false; pnode->win=false; pnode->endword=false; for (int i=0; i<26; ++i) pnode->child[i]=NULL; return pnode; }; //Nina void add1(string s, node *pnode) { for (int i=0; i<s.size(); ++i) { int idx=s[i]-'a'; if (!pnode->child[idx]) pnode->child[idx]=getnode(s[i],pnode->depth+1); pnode->endword=false; pnode=pnode->child[idx]; pnode->k1=true; } pnode->endword=true; } //Emilia void add2(string s, node *pnode) { for (int i=0; i<s.size(); ++i) { int idx=s[i]-'a'; if (!pnode->child[idx]) pnode->child[idx]=getnode(s[i],pnode->depth+1); pnode->endword=false; pnode=pnode->child[idx]; pnode->k2=true; } pnode->endword=true; } bool dfs(node *pnode) { //game end if (pnode->depth%2==0 && !pnode->k2) return true; if (pnode->depth%2==1 && !pnode->k1) return false; if (pnode->endword) { if (pnode->depth%2==1) return true; else return false; } //game continue if (pnode->depth%2==0) { bool win=false; for (int i=0; i<26; ++i) { if (pnode->child[i]) win|=dfs(pnode->child[i]); } return win; } else { bool win=true; for (int i=0; i<26; ++i) { if (pnode->child[i]) win&=dfs(pnode->child[i]); } return win; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; string s; struct node *trie = getnode('*',0); trie->k2=true; cin>>n; while (n--) cin>>s, add1(s,trie); cin>>n; while (n--) cin>>s, add2(s,trie); if (dfs(trie)) cout<<"Nina"; else cout<<"Emilija"; }

Compilation message (stderr)

Main.cpp: In function 'void add1(std::string, node*)':
Main.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i=0; i<s.size(); ++i) {
      |                   ~^~~~~~~~~
Main.cpp: In function 'void add2(std::string, node*)':
Main.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i=0; i<s.size(); ++i) {
      |                   ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...