# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116850 | nhimnam120 | Lozinke (COCI17_lozinke) | C++14 | 0 ms | 0 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>
#define fi first
#define se second
using namespace std;
map<string, long long> cnt;
vector<pair<long long,string> > inpp;
set<string> inp;
signed main(){
ios_base::sync_with_stdio(false);
cni.tie(0);
long long n;
cin >> n;
for(int i=0;i<n;i++){
string a;
cin >> a;
cnt[a]++;
inp.insert(a);
}
long long ans=0;
for(auto x: inp){
inpp.push_back({x.size(),x});
}
sort(inpp.begin(),inpp.end());
for(int i=0;i<inpp.size();i++){
long long pos=0;
string a=inpp[i].se;
ans=ans+(cnt[a]*(cnt[a]-1));
while(inpp[pos].fi<inpp[i].fi){
string b=inpp[pos].se;
for(int k=0;k<inpp[i].fi-inpp[pos].fi+1;k++){
if(a[k]==b[0]){
long long test=0;
for(int j=0;j<inpp[pos].fi;j++){
if(a[k+j]!=b[j]){
test=1;
break;
}
}
if(test==0){
ans=ans+cnt[a]*cnt[b];
break;
}
}
}
pos++;
}
}
cout << ans;
}