# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
49906 | computerbox | Lozinke (COCI17_lozinke) | C++14 | 5 ms | 468 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.
//ID:computerbox --> Hajiyev Huseyn
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);/*cin.tie(0); cout.tie(0);*/
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000
using namespace std;
struct vertex
{
set<ll>leaf;
ll next[30];
};
ll sz;
vertex t[3000000];
void add_string(string stroka,ll index)
{
ll v=0;
for(ll i=0;i<(ll)stroka.size();i++)
{
char c=stroka[i]-'a';
if(t[v].next[c]==-1)
{
memset(t[sz].next,255,sizeof t[sz].next);
t[v].next[c]=sz++;
}
v=t[v].next[c];
t[v].leaf.insert(index);
}
}
ll find(string stroka)
{
ll maxa=0;
ll v=0;
ll cnt=0;
for(ll i=0;i<(ll)stroka.size();i++)
{
char c=stroka[i]-'a';
if(t[v].next[c]==-1)return 0;
v=t[v].next[c];
}
return (t[v].leaf.size()-1);
}
ll n;
vector<string>nuj;
string stroka;
string abc;
int main(){
FAST_READ;
cin.tie(0);
cin>>n;
for(ll i=0;i<=n;i++)
{
memset(t[i].next,-1,sizeof t[i].next);
}
sz=1;
for(ll i=1;i<=n;i++)
{
cin>>stroka;
string neww="";
for(ll j=0;j<(ll)stroka.size();j++)
{
neww="";
for(ll jj=j;jj<(ll)stroka.size();jj++)
{
neww+=stroka[jj];
//debt(neww,j);
add_string(neww,i);
}
}
nuj.pb(stroka);
}
ll cnt=0;
for(ll i=0;i<nuj.size();i++)
{
ll ans=find(nuj[i]);
cnt=cnt+ans;
}
cout<<cnt<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |