Queen Attack BitMasking


#1
ll row = A.size();
ll col = A[0].length();

vector<vector<int>>ans(row, vector<int>(col, 0));

bool flag;

for (ll i = 0; i < row; i++)
{

    flag = 0;
    for (ll j = 0; j < col; j++)
    {
        ans[i][j] += flag;
        flag |= (A[i][j] - '0');
    }
    flag = 0;
    for (ll j = col - 1; j > -1; j--)
    {
        ans[i][j] += flag;
        flag |= (A[i][j] - '0');
    }
}

for (ll i = 0; i < col; i++)
{

    flag = 0;
    for (ll j = 0; j < row; j++)
    {
        ans[j][i] += flag;
        flag |= (A[j][i] - '0');
    }
    flag = 0;
    for (ll j = row - 1; j > -1; j--)
    {
        ans[j][i] += flag;
        flag |= (A[j][i] - '0');
    }
}

// southeast
ll mask = 0;
ll tot = (1 << col) - 1;
for (ll i = 0; i < row; i++)
{
    for (ll j = 0; j < col; j++)
        ans[i][j] += ((mask >> j) & 1);
    for (ll j = 0; j < col; j++)
        mask |= ((A[i][j] - '0') << j);
    mask <<= 1;
    mask &= (tot);
}

// southwest
mask = 0;
for (ll i = 0; i < row; i++)
{
    for (ll j = 0; j < col; j++)
        ans[i][j] += ((mask >> j) & 1);
    for (ll j = 0; j < col; j++)
        mask |= ((A[i][j] - '0') << j);
    mask >>= 1;
    mask &= (tot);
}

// northeast
mask = 0;
for (ll i = row - 1; i > -1; i--)
{
    for (ll j = 0; j < col; j++)
        ans[i][j] += ((mask >> j) & 1);
    for (ll j = 0; j < col; j++)
        mask |= ((A[i][j] - '0') << j);
    mask <<= 1;
    mask &= (tot);
}

// northwest
mask = 0;
for (ll i = row - 1; i > -1; i--)
{
    for (ll j = 0; j < col; j++)
        ans[i][j] += ((mask >> j) & 1);
    for (ll j = 0; j < col; j++)
        mask |= ((A[i][j] - '0') << j);
    mask >>= 1;
    mask &= (tot);
}

return ans;

i tried checking for multiple cases but couldnt find the flaw. IB gives a 21 line testcase i cant makeout anything from it. can someone please give me a small testcase??
logic; horizontal and vertical is easy for diagonals i have used bitmasking