Submission #138890

# Submission time Handle Problem Language Result Execution time Memory
138890 2019-07-30T19:10:14 Z vladciuperceanu Lozinke (COCI17_lozinke) C++14
100 / 100
276 ms 2532 KB
#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

lozinke.cpp: In function 'int main()':
lozinke.cpp:31:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int ind=0; ind<s[i].size(); ind++)
                         ~~~^~~~~~~~~~~~
lozinke.cpp:32:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int lung=1; ind+lung<=s[i].size(); lung++)
                              ~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1020 KB Output is correct
2 Correct 2 ms 888 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 4 ms 888 KB Output is correct
5 Correct 11 ms 1016 KB Output is correct
6 Correct 17 ms 1016 KB Output is correct
7 Correct 21 ms 1016 KB Output is correct
8 Correct 25 ms 1144 KB Output is correct
9 Correct 96 ms 1400 KB Output is correct
10 Correct 128 ms 1496 KB Output is correct
11 Correct 153 ms 1788 KB Output is correct
12 Correct 247 ms 1912 KB Output is correct
13 Correct 244 ms 2168 KB Output is correct
14 Correct 227 ms 2532 KB Output is correct
15 Correct 276 ms 2168 KB Output is correct
16 Correct 200 ms 1272 KB Output is correct
17 Correct 89 ms 1272 KB Output is correct
18 Correct 70 ms 1196 KB Output is correct
19 Correct 219 ms 2040 KB Output is correct
20 Correct 132 ms 1272 KB Output is correct