Cod sursă (job #565540)

Utilizator avatar VladTZY Tiganila Vlad VladTZY IP ascuns
Problemă Beculețe (clasele 9-10) Compilator cpp | 1.12 kb
Rundă Arhiva de probleme Status evaluat
Dată 30 sept. 2020 23:02:42 Scor 10
#include <fstream>

#define NMAX 50050

using namespace std;

ifstream f("beculete.in");
ofstream g("beculete.out");

int n, k, col, line, on_off;
int a[NMAX / 32];

int Get(int pos)
{
    int val = (a[pos >> 5] >> (pos & 31)) & 1;
    return val;
}
void Set(int pos, int val)
{
    int ant = ~(1 << (pos & 31));
    a[pos >> 5] = (a[pos >> 5] & ant) ^ (val << (pos & 31));
}
void WorkOnIt(int i)
{
    for(int bit = i / 32; bit >= 1; bit--)
    {
        a[bit] = a[bit] ^ (a[bit] << 1);
        a[bit] = a[bit] ^ (a[bit - 1] >> 31);
    }
    a[0] = a[0] ^ (a[0] << 1);
}

int main()
{
    f >> n >> k;

    Set(1, 1);
    for(int i = 2; i <= n; i++)
    {
        int last = Get(i - 1);

        WorkOnIt(i);
        Set(i, last);

        /*for(int j = 1; j <= i; j++)
            g << Get(j) << " ";
        g << "\n";*/

        while(line <= i && k >= 0)
        {
            if(line == i)
                Set(col, on_off);

            f >> line >> col >> on_off;
            k--;
        }
    }

    for(int i = 1; i <= n; i++)
        g << Get(i) << " ";
    return 0;
}