# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
152769 | phillip | Lozinke (COCI17_lozinke) | C++14 | 54 ms | 19860 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;
long long the,n;
string s[100004];
struct trie
{
int en=0,cnt=0;
trie *a[27]={0};
void inse(int x,int y)
{
if (y==s[x].size())
{
en++;
cnt++;
return;
}
int ind=s[x][y]-'a';
if (a[ind]==0) a[ind]=new trie;
a[ind]->inse(x,y+1);
}
void ans(int x,int y)
{
the+=en;
en=0;
if (y==s[x].size()) return ;
if (a[s[x][y]-'a']!=0) a[s[x][y]-'a']->ans(x,y+1);
return ;
}
void rep(int x,int y)
{
en=cnt;
if (y==s[x].size()) return ;
if (a[s[x][y]-'a']!=0) a[s[x][y]-'a']->rep(x,y+1);
return ;
}
};
trie tr;
int main()
{
cin>>n;
for (int i=0;i<n;i++)
{
cin>>s[i];
tr.inse(i,0);
}
for (int i=0;i<n;i++)
{
for (int j=0;j<s[i].size();j++) tr.ans(i,j);
for (int j=0;j<s[i].size();j++) tr.rep(i,j);
}
cout<<the-n;
return 0;
}
//Sent from Mail for Windows 10
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |