# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
138890 | vladciuperceanu | Lozinke (COCI17_lozinke) | C++14 | 276 ms | 2532 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 <string>
#include <set>
#include <map>
using namespace std;
int n,i,sol;
string s[20005],aux;
set<string> secv;
map<string, int> m;
int cmp(string a, string b)
{
if (a.size() != b.size())
return a.size() < b.size();
else
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++)
{
secv.clear(); secv.insert(s[i]);
for (int ind=0; ind<s[i].size(); ind++)
for (int lung=1; ind+lung<=s[i].size(); lung++)
secv.insert(s[i].substr(ind, lung));
for (set<string>:: iterator it=secv.begin(); it!=secv.end(); it++)
if (m.find(*it) != m.end())
sol += m[*it];
if (m.find(s[i]) != m.end())
m[s[i]]++;
else
m[s[i]] = 1;
}
for (map<string, int>::iterator it=m.begin(); it!=m.end(); it++)
sol += (it->second)*(it->second-1)/2;
cout << sol;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |