# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241108 | DavidDamian | Lozinke (COCI17_lozinke) | C++11 | 46 ms | 23804 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |