Cod sursa(job #3177468)

Utilizator paull122Paul Ion paull122 Data 29 noiembrie 2023 10:56:39
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ifstream fin("dtcsu.in");
ofstream fout("dtcsu.out");
#define HASH_BASE 264
#define HASH_SIZE1 666013

int computehash(ll x,int hbase,int hsize)
{
    int strhash=0;
    while(x)
    {
        strhash = (strhash * hbase + x%10)%hsize;
        x/=10;
    }
    return strhash;
}

unordered_map<int,bool> M1,M2;

int main()
{
    for(int i=1;i<=276997;i++)
    {
        ll x;
        fin >> x;
        M1[computehash(x,HASH_BASE,HASH_SIZE1)]=1;
    }
    int q;
    fin >> q;
    int cnt=0;
    while(q--)
    {
        int x;
        fin >> x;
        cnt += M1[computehash(x,HASH_BASE,HASH_SIZE1)];
    }
    fout << cnt;
}