Pentru această operație este nevoie să te autentifici.

Cod sursă (job #578795)

Utilizator avatar nicolai.vlada Vlada Nicolai nicolai.vlada IP ascuns
Problemă Beculețe (clasele 9-10) Compilator cpp-32 | 1,14 kb
Rundă Arhiva de probleme Status evaluat
Dată 20 ian. 2021 17:33:17 Scor 100
#include <fstream>
 
#define NMAX 50050
 
using namespace std;
 
ifstream f("beculete.in");
ofstream g("beculete.out");
 
int n, k, col, line, on_off;
unsigned a[NMAX / 32];
 
int Get(int pos)
{
    int val = (a[pos >> 5] >> (pos & 31)) & 1;
    return val;
}
void Set(int pos, int val)
{
    unsigned 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;
}