https://code.google.com/codejam/contest/5254486/dashboard#s=p2 i am unable to solve the large subtask of this problem.. i solved the small one using brute force.. please help me understand the logic behind this problem.. thanks.

# | User | Rating |
---|---|---|

1 | tourist | 3882 |

2 | maroonrk | 3539 |

3 | Benq | 3513 |

4 | MiracleFaFa | 3466 |

5 | ksun48 | 3462 |

6 | ecnerwala | 3446 |

7 | slime | 3428 |

8 | Um_nik | 3426 |

9 | jiangly | 3401 |

10 | greenheadstrange | 3393 |

# | User | Contrib. |
---|---|---|

1 | awoo | 192 |

2 | -is-this-fft- | 191 |

3 | Monogon | 184 |

4 | YouKn0wWho | 182 |

4 | Um_nik | 182 |

6 | antontrygubO_o | 171 |

7 | maroonrk | 169 |

8 | kostka | 165 |

9 | SecondThread | 164 |

9 | errorgorn | 164 |

https://code.google.com/codejam/contest/5254486/dashboard#s=p2 i am unable to solve the large subtask of this problem.. i solved the small one using brute force.. please help me understand the logic behind this problem.. thanks.

↑

↓

Codeforces (c) Copyright 2010-2022 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/24/2022 22:00:56 (h3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

I will try to explain my approach which I used to solve it. Since, the three operations involved are all bitwise operations, the final result of each bit in the answer depends only on its own initial value and not on any other bit. So, we can try to find the probability of getting a '1' in each bit. Since, the maximum value can be 10**9, I used 32 bits.

Now, for finding the probability of getting a '1' in a particular bit, can be solved using DP. Lets have an array

P[2]in which P[0] denotes the probability of the bit being 0 and P[1] denotes the probability of the bit being 1. Initially, before passing it to any of the machines, the values of P[0] & P[1] will either be 0.0 and 1.0 or 1.0 and 0.0 respectively based on whether the particular bit is 1 or 0 in the given value x. Now we run it through all the N machines.Now to find P[0] and P[1] after we pass it through a machine, we need to use the same bit in 'k' for which we are finding the answer since only this bit determines the answer. Also, the machine can either do 'AND', 'OR' or 'XOR' operation and so using these information we can find the new P[0] and P[1] value after we pass through a single machine. We repeat this process for all N machines and for all 32 bits. So, the total complexity will be

O(N).After we find the individual probability of each bit, the answer will be sum of

pow(2,i)*P[i][1]for0≤i≤31. Here P[i][1] denotes probability of ith bit being '1'.My C++ code

thanks for such a nice and clear explanation.. :)

Thanks for the explanation but i couldn't understand the login used inside for loop for N machines to calculate n0, n1; Thanks;

Consider the following block in the code:

If the current bit we are considering in 'k' is a '1' then this block will be executed. As we know there are 3 operations — AND, OR and XOR. When we AND '1' with 'x', it becomes 'x'. So, with probability

p[0]*(a/100)'0' will become '0' itself and with probabilityp[1]*(a/100)'1' will become '1' itself.Next we will consider the OR operation with probability (b/100). When we OR '1' with 'x' we get '1'. So, the new probability of '1' will be

(b/100)*(sum of p[0] and p[1])since both '0' and '1' will result in '1' when ORed.Finally, when we XOR '1' with 'x' we get '1-x' and so n0 will be

p[1]*(c/100)since '1' will change to '0' when we XOR it and vice versa for n1.With similar logic we do the else part when the current bit is not set in 'k' and we are done. Hope it is clear now.

Thank you. You are the best teacher.

very well explained! thanks a lot!