Can anyone help me with this problem?

I have learnt sprague grundy numbers recently.

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

1 | Benq | 3813 |

2 | tourist | 3768 |

3 | maroonrk | 3570 |

4 | Radewoosh | 3535 |

5 | fantasy | 3526 |

6 | jiangly | 3523 |

7 | Um_nik | 3522 |

8 | orzdevinwang | 3441 |

9 | cnnfls_csy | 3427 |

10 | zh0ukangyang | 3423 |

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

1 | awoo | 180 |

2 | -is-this-fft- | 179 |

3 | nor | 169 |

4 | Um_nik | 167 |

5 | SecondThread | 164 |

6 | maroonrk | 163 |

7 | adamant | 162 |

8 | kostka | 161 |

9 | YouKn0wWho | 158 |

10 | errorgorn | 155 |

Can anyone help me with this problem?

I have learnt sprague grundy numbers recently.

↑

↓

Codeforces (c) Copyright 2010-2023 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jan/27/2023 05:06:24 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

First, to use NIM game technique you need independent games. You can think of the game as moving coins from i to 2*i, 3*i or 5*i. And each coins is independent from the rest.

Now, you just need to find the grundy number associated with each coin. To do this you can build an graph. Where each position of the array is a node, and an edge represents to which positions you can move the coin. For example for a array of size 10:

In red is the grundy number. Basically if you can't go anywhere it is 0, otherwise is the smallest integer that you can't directly reach.

To solve the problem you can pre-calculate the grundy number for each position with the graph. Then do XOR for the grundy number of each coin.

"Then do XOR for the grundy number of each coin."

for each coin or position?

For each coin.

For example:

0 3 0 1 2 0 0 0 0 0

You have 3 coins in position 2, 1 coin in position 4 and 2 in position 5. So you should do:

`grundy(2) XOR grundy(2) XOR grundy(2) XOR grundy(4) XOR grundy (5) XOR grundy(5)`

Obs: Just remember that

`a XOR a = 0`

, so the above is equivalent to:`grundy(2) XOR grundy(5)`