Submission #491622

#TimeUsernameProblemLanguageResultExecution timeMemory
491622blueLozinke (COCI17_lozinke)C++17
100 / 100
485 ms16532 KiB
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
using namespace std;

map<string, int> ct;

void map_insert(string s)
{
    if(ct.find(s) == ct.end()) ct[s] = 1;
    else ct[s]++;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;

    vector<string> s(N);
    for(int i = 0; i < N; i++)
    {
        cin >> s[i];

        int k = int(s[i].size());

        set<string> z;

        for(int j = 0; j < k; j++)
            for(int l = j; l < k; l++)
                z.insert(s[i].substr(j, l-j+1));

        for(string t: z)
            map_insert(t);
    }

    int ans = 0;

    for(int i = 0; i < N; i++)
    {
        // cerr << i << " : " << ct[s[i]] << '\n';
        ans += ct[s[i]] - 1;
    }

    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...