# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
144273 | Divia | Lozinke (COCI17_lozinke) | C++14 | 262 ms | 2392 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 <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
//ifstream cin("lozinke.in");
//ofstream cout("lozinke.out");
int n,i,j,k,sol;
string s[20005],aux;
set <string> sett;
map <string,int> mapp;
set <string> ::iterator it;
map <string,int> ::iterator itt;
int cmp(string a,string b){
if(a.size()!=b.size())return a.size()<b.size();
return a<b;
}
int main(){
cin>>n;
for(i=1;i<=n;i++)
cin>>s[i];
sort(s+1,s+n+1,cmp);
for(i=1;i<=n;i++){
sett.clear();
for(j=0;j<s[i].size();j++){
aux.erase(aux.begin(),aux.end());
for(k=j;k<s[i].size();k++){
aux.push_back(s[i][k]);
sett.insert(aux);
}
}
for(it=sett.begin();it!=sett.end();it++)
if(mapp.find(*it)!=mapp.end())
sol+=mapp[*it];
if(mapp.find(s[i])!=mapp.end())
mapp[s[i]]++;
else mapp[s[i]]=1;
}
for(itt=mapp.begin();itt!=mapp.end();itt++)
sol+=(itt->second)*(itt->second-1)/2;
cout<<sol;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |