Cod sursa(job #1497145)

Utilizator fluture.godlikeGafton Mihnea Alexandru fluture.godlike Data 6 octombrie 2015 10:47:00
Problema Oite Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.85 kb
#include <cstdio>
#include <vector>

#define NMAX 1027
#define MOD 69257
#define LL long long
#define DIM 10007

using namespace std;
unsigned int n, sum, v[NMAX], sol, ans, poz1;
char buff[DIM];
struct tabel
{
    int val;
    int x;
    int y;
} tmp;
vector <tabel> dsp[MOD];

void citeste(unsigned int &nr)
{
    nr = 0;
    while(buff[poz1] < '0' || buff[poz1] > '9')
    {
        ++poz1;
        if(poz1 == DIM)
        {
            poz1 = 0;
            fread(buff, 1, DIM, stdin);
        }
    }
    while(buff[poz1] >= '0' && buff[poz1] <= '9')
    {
        nr = nr*10 + buff[poz1]-'0';
        ++poz1;
        if(poz1 == DIM)
        {
            poz1 = 0;
            fread(buff, 1, DIM, stdin);
        }
    }
}

int main()
{
    freopen("oite.in", "r", stdin);
    freopen("oite.out", "w", stdout);
    //scanf("%d %d", &n, &sum);
    citeste(n);
    citeste(sum);
    for(int i = 1; i<= n; ++i) citeste(v[i]);//scanf("%d", &v[i]);
    for(int i = 1; i<= n; ++i)
    {
        for(int j = i+1; j<= n; ++j)
        {
            tmp.val = v[i]+v[j];
            tmp.x = i;
            tmp.y = j;
            int poz = tmp.val%MOD;
			dsp[poz].push_back(tmp);
        }
    }
    for(int i = 1; i<= n; ++i)
    {
        for(int j = i+1; j<= n; ++j)
        {
        	int poz = (sum - v[i] - v[j])%MOD;
        	int sze = dsp[poz].size();
        	for(int k = 0; k< sze; ++k)
			{
				if(dsp[poz][k].val == sum - v[i] - v[j])
				{
					if(dsp[poz][k].x == i) continue;
					if(dsp[poz][k].x == j) continue;
					if(dsp[poz][k].y == i) continue;
					if(dsp[poz][k].y == j) continue;
					//printf("%d %d %d %d\n", i, j, dsp[poz][k].x, dsp[poz][k].y);
					ans++;
					if(ans == 6)
					{
						sol++;
						ans = 0;
					}
				}
			}
        }
    }
    printf("%d\n", sol);
    return 0;
}