Submission #241108

#TimeUsernameProblemLanguageResultExecution timeMemory
241108DavidDamianLozinke (COCI17_lozinke)C++11
100 / 100
46 ms23804 KiB
#include <bits/stdc++.h> using namespace std; ///Trie struct node { int bucket[27]; int wordCount; int last; }; node trie[2000005]; int actNode=0; void Insert(string s,int id) { for(int a=0;a<s.size();a++){ int u=0; for(int i=a;i<s.size();i++){ int letter=s[i]-'a'; if(trie[u].bucket[letter]==0) trie[u].bucket[letter]=++actNode; u=trie[u].bucket[letter]; if(trie[u].last!=id) trie[u].wordCount++; trie[u].last=id; } } } int query(string s) { int u=0; for(int i=0;i<s.size();i++){ int letter=s[i]-'a'; if(trie[u].bucket[letter]==0) return 0; u=trie[u].bucket[letter]; } return trie[u].wordCount-1; } int n; vector<string> A; int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ string s; cin>>s; Insert(s,i); A.push_back(s); } int total=0; for(string s: A){ total+=query(s); } cout<<total<<'\n'; return 0; }

Compilation message (stderr)

lozinke.cpp: In function 'void Insert(std::__cxx11::string, int)':
lozinke.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int a=0;a<s.size();a++){
                 ~^~~~~~~~~
lozinke.cpp:16:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=a;i<s.size();i++){
                     ~^~~~~~~~~
lozinke.cpp: In function 'int query(std::__cxx11::string)':
lozinke.cpp:30:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++){
                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...