Submission #79939

#TimeUsernameProblemLanguageResultExecution timeMemory
79939luckyboyLozinke (COCI17_lozinke)C++14
55 / 100
1080 ms66560 KiB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 20005
#define maxm 500005
#define pii pair <int,int>
#define Task "Lozinke"
using namespace std;
int n;
string s[maxn];
map <string,int> dd,dd1;
map <string,bool> ok[maxn];
long long ans;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    cin >> n;
    FOR(i,1,n)
    {
        cin >> s[i];
        int temp = s[i].size();
        FOR(j,1,temp)
            FOR(pos,0,temp - j)
            {
                string ww = s[i].substr(pos,j);
                if (ok[i][ww]) continue;
                ok[i][ww] = 1;
                ans += dd[ww];
            }
        FOR(j,1,temp)
           FOR(pos,0,temp - j)
            {
                string ww = s[i].substr(pos,j);
                ok[i][ww] = 0;
            }
        ++dd[s[i]];
    }
    FORD(i,n,1)
    {
        int temp = s[i].size();
        FOR(j,1,temp)
            FOR(pos,0,temp - j)
            {
                string ww = s[i].substr(pos,j);
                if (ok[i][ww]) continue;
                ok[i][ww] = 1;
                ans += dd1[ww];
            }
        ++dd1[s[i]];

    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...