Cod sursa(job #2795536)

Utilizator mihneazzzMacovei Daniel mihneazzz Data 6 noiembrie 2021 15:45:37
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>
#define N 10000005
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");
char a[N],s[N];
unordered_map<long long,bool> M;

int main()
{
    int i,j,lgmax=-1,l,ct=0;
    fin>>a;
    while(fin>>s)
    {
        long long p=1,x=0;
        int n=strlen(s);
        for(i=n-1;i>=0;i--)
        {
            x+=(s[i]-'a'+1)*p;
            p*=4;
        }
        M[x]=1;
        lgmax=max(lgmax,n);
        cout<<x<<" ";
    }
    for(l=1;l<=lgmax;l++)
    {
        long long x=0,p=1;
        for(i=l;i>=0;i--)
           x+=(a[i]-'a'+1)*p,p*=4;
        if(M[x]) ct++;
        for(i=1;a[i+l-1];i++)
           {x=x%p*4+a[i]-'a'+1;
           if(M[x]) ct++,cout<<l<<"a",cout<<x<<" ";
           }
    }
    fout<<ct;
    return 0;
}