Cod sursă (job #119209)

Utilizator avatar Claudiu Dan Claudiu Claudiu IP ascuns
Problemă Beculețe (clasele 9-10) Compilator cpp | 1,30 kb
Rundă Tema 15 clasele 9-10 2014/15 Status evaluat
Dată 17 feb. 2015 22:04:56 Scor 0
#include <stdio.h>

using namespace std;

const unsigned short int N=50000/63 + 1;
const unsigned short int D=10000;
unsigned long long a[N];
short int na;
short int x[D],y[D],v[D];

int main()
{
    FILE *in=fopen("beculete.in","r");
    FILE *out=fopen("beculete.out","w");

    unsigned short int n,d,i,j,p;
    unsigned long long bit1,bit2,k;

    fscanf(in,"%hd%hd",&n,&d);
    for(i=0;i<d;i++)
    {
        fscanf(in,"%hd%hd%hd",&x[i],&y[i],&v[i]);
        x[i]--;
        y[i]--;
    }

    na=1;
    a[0]=1LLU;
    p=0;
    for(i=1;i<n;i++)
    {
        bit1=bit2=0LLU;
        for(j=0;j<na;j++)
        {
            bit2=(a[j]&(1LLU<<63))>>63;
            a[j]^=a[j]<<1;
            a[j]^=bit1;
            bit1=bit2;
            while(x[p]==i && y[p]>=64*j && y[p]<64*(j+1))
            {
                a[j]-=1LLU<<(y[p]-64*j);
                a[j]+=(unsigned long long)(v[p]<<(y[p]-64*j));
                p++;
            }
        }
        if(bit1)
            a[na++]=1LLU;


    }

    i=0;
    j=0;
    while(i<n)
    {
        k=0;
        while(i<n && k<64)
        {
            fprintf(out,"%d",(a[j]&(1LLU<<k))>>k);
            if(i<n-1) fprintf(out," ");
            k++;
            i++;
        }
        j++;
    }
    return 0;
}