AND Reachability DP Problem

Magar main() function ke andar ese define nai karte hai agr static array ko main() ke andar initialize kr rhe hai tab …

global scope mein allow nahi hota aisa na ,waha const banana mandatory hain.

in main it is allowed.
but then also static array ka size nahi badal skate

1 Like

ans|=(((a[y]>>j) & 1) && go[x][j]<=y);

Bhaiya, iss condition meh go[x][j]<=(y-x) esa hona tha na…

no…
we are iterting to all set bit position of y (say j).
and then we are checking what is the smallest index that we can reach from x whose jth bit position is set.

if we get any index which is <=y then we can clearly reach to y.(first we reach to that smallest index and because it (value at that index) has atleast one bit common with a[y] we can reach to y from there using that common bit)
answer will be true.

((a[y]>>j) & 1) <- this is checking jth bit is set or not && go[x][j]<=y <- this is checking whether smallest index reachable from x (whose value jth bit is set )is less than equal to y or not.

Accha…toh agar mujhe smallest index nikal na rahta between x and y tab meh esa likhta…

for(int j=0;j<=19;j++){
    if((a[y]>>j) & 1)
        ans=min(ans,go[x][j]);
    }

ha correct. . . . . . . .

Bhaiya, pahle CB wala code apko samjh aya tha kya?

maine wo dekha hi nahi hai…
mujhe erichto ka logic kaafi logical aur simple laga tha isliye mein usi se solve kiya.

Bhaiya, errichto wala bhi thoda alag hai…maine same bataya tha codeforces ke editorial se magr thoda alag hai…

dont know mujhe hint mil gya tha approach ki wahi kaafi tha.

for(int i=n-1;i>=0;i--){

        for(int j=0;j<=19;j++){

            go[i][j]=n;

        }

Bhaiya, for loop ke andar har baar go[i][j] ko n se initialize karne ka kya mtlb hai…maine toh ekbaar pahle hi initialize kar diye the…magr fir se same chiz…samjh nai aya yeh

ha intitially max value n ya any number > n se intitilaise kar rahe hai . to indicate that as of now we cannot reach anywhere.

but later in other loop
we are updating these value
dp[i][j]=min(dp[i][j],somehting else) this will update its value

1 Like

Bhaiya, esa agar hard question rha codeforces peh tab toh contest meh participate karna, bhul jana hi behtar hai…

no bro aise nahi karna chaiye , participate reguraly and focus on learning instead of rating or anything else .

baaki ye problem tough to thi (div1 c ka matlab hai div2 ka f o my gaaaad)
no doubt khtrnak sawal tha

1 Like

Bhaiya, aap kese div(1,2,3…) and (a,b,c…) se question ko judge kar rhe hai? Thoda mujhe bhi batayiyega, inn sab ka question ke sath kya taluk hai…

Itna pata tha ki div1 A hard hai sabse jada…kyun ki maine Nauuo and Cards ka problem kara tha jo mujhe 12 din laga samjh ne meh…

div2 ki difficulty c/d div1 ke a ke barabr hoti hai.
usi hisab se e-f ke equivalent bol raha tha.

Toh fir, beginner ko pahle div1 ya div 2 karna chahiye?

div 2 n div 3. . . . . . …

Esa hai kya difficulty level:

Div 1>Div 2>Div 3

And, A<B<C<D<E<F (in every Div)

ha …
baaki abhi ye doubt to clear ho gya na?