Cod sursa(job #3319066)

Utilizator ioanxhIoan Budeanu ioanxh Data 30 octombrie 2025 14:07:32
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,inline")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define fast ios_base::sync_with_stdio(0);f.tie(0);g.tie(0);
#define setinf(x) memset(x,0x3f3f3f3f,sizeof(x));
#define set0(x) memset(x,0,sizeof(x));
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define fi first
#define se second
#define DD 100001
#define nl '\n'
using namespace std;
const string file="abc2";
ifstream f(file+".in");
ofstream g(file+".out");
//#define f cin
//#define g cout
string s,t;
unordered_map<ll,bool> mp;
const int mod=1e9+9;
ll r;
int main(){
    f>>s;
    int l=0;
    while (f>>t) {
        ll hash=0;
        for (char c:t) hash=(hash*1315423911+(c-'a'))%mod;
        mp[hash]=1;
        if (!l) l=t.size();
    }
    ll p=1;
    for (int i=1; i<l; ++i)
        p=(p*1315423911)%mod;
    ll hash=0;
    for (int i=0; i<l; ++i) {
        hash=(hash*1315423911+(s[i]-'a'))%mod;
    }
    if (mp.count(hash)) ++r;
    for (int i=l; i<s.size(); ++i) {
        hash=(hash-(s[i-l]-'a')*p%mod+mod)%mod;
        hash=(hash*1315423911+(s[i]-'a'))%mod;
        if (mp.count(hash)) ++r;
    }
    g<<r;
    system("pause");
    return 0;
}