# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
141684 | Mihnea | Lozinke (COCI17_lozinke) | C++14 | 270 ms | 2296 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<map>
#include<string>
#include<set>
#include<algorithm>
using namespace std;
int n,s;
string st[20010],sc;
set <string> a;
map <string,int> b;
int cmp(string a,string b) {
if (a.size()!=b.size())
return a.size()<b.size();
else
return a<b;
}
int main(){
cin>>n;
int s=0;
for(int i=1;i<=n;i++)
cin>>st[i];
sort(st+1,st+n+1,cmp);
for(int i=1;i<=n;i++) {
a.clear();
for(int j=0;j<st[i].size();j++) {
sc.erase( sc.begin(),sc.end() );
for(int k=j;k<st[i].size();k++) {
sc.push_back(st[i][k]);
a.insert(sc);
}
}
for(set<string>::iterator it=a.begin();it!=a.end();it++) {
if (b.find(*it)!=b.end())
s+=b[*it];
}
if(b.find(st[i])==b.end())
b[st[i]]=1;
else
b[st[i]]++;
}
int L=1;
for(int i=2;i<=n;i++) {
if(st[i]==st[i-1])
L++;
else
L=1;
s+=L-1;
}
cout<<s;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |