Cod sursa(job #1570280)

Utilizator redcrocodileIlies Andreea redcrocodile Data 16 ianuarie 2016 12:18:58
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <bitset>
#include <cstring>
using namespace std;
ifstream f("dtcsu.in");
ofstream g("dtcsu.out");
bitset<5000000> bit[3][50];
int m,i,k;
long long x,q;
int aparitie(long long x)
{
    int h1,h2,h3,hh1,hh2,hh3;
    h1=x%500000; hh1=x/500000;
    h2=x%250000; hh2=x/250000;
    h3=x%100000; hh3=x/100000;
    if(bit[0][h1][hh1]==1 and bit[1][h2][hh2]==1 and bit[2][h3][hh3]==1) return 1; else return 0;
}
void apare(long long x)
{
   if(aparitie(x)) k++;
}
void inserez(long long x)
{
    int h1,h2,h3,hh1,hh2,hh3;
    h1=x%500000; hh1=x/500000;
    bit[0][h1][hh1]=1;
    h2=x%250000; hh2=x/250000;
    bit[1][h2][hh2]=1;
    h3=x%100000; hh3=x/100000;
    bit[2][h3][hh3]=1;
}
string s;
int main()
{
    int j,n;
    for (i=1;i<=276997;i++)
    {
        getline(f,s);
        x=0;
        n=s.length();
        for(j=0;j<n;j++)
            x=x*10+s[j]-'0';
        inserez(x);
    }
    getline(f,s);
    n=s.length();
    for(j=0;j<n;j++)
        m=m*10+s[j]-'0';
    for(i=1;i<=m;i++)
    {
        getline(f,s);
        q=0;
        n=s.length();
        for(j=0;j<n;j++)
            q=q*10+s[j]-'0';
        apare(q);
    }
    g<<k;
    return 0;
}