Cod sursa(job #2872413)

Utilizator tomaionutIDorando tomaionut Data 16 martie 2022 22:18:57
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <bits/stdc++.h>
#define P 15029
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");
char s[10000005];
char cuv[30];
vector <int> a[P];
void Add(int x)
{
    int r = x % P;
    a[r].push_back(x);
}

bool Cauta(int x)
{
    int r = x % P;
    for (auto w : a[r])
        if (x == w)
            return 1;
    return 0;
}

int main()
{   
    int cod, h1, i, pow, len, sol = 0;
    fin >> s;
    while (fin >> cuv)
    {
        h1 = 0;
        pow = 1;
        len = strlen(cuv);
        for (i = 0; cuv[i]; i++, pow *= 2)
            h1 += (pow * (cuv[i] - 'a'));
        if (Cauta(h1) == 0)
            Add(h1);
    }
    pow = 1;
    h1 = 0;
    for (i = 0; i < len; i++, pow *= 2)
        h1 += pow * (s[i] - 'a');
    sol += Cauta(h1);
    pow /= 2;
    for (i = len; s[i]; i++)
    {
        h1 /= 2;
        h1 += pow * (s[i] - 'a');
        sol += Cauta(h1);
    }
    fout << sol << "\n";

    return 0;
}