G: Cuboid Slicing Game
https://open.kattis.com/contests/s82cve/problems/cuboidslicinggame
Last updated
https://open.kattis.com/contests/s82cve/problems/cuboidslicinggame
Last updated
This problem uses the . This solution assumes the reader is familiar with this method; if not, check out the Wikipedia page and stay tuned for an upcoming ICPC workshop on it!
Let be the maximum length of a cuboid in a dimension. Then the Sprague-Grundy recurrence can be naively implemented using dynamic programming in . Since in the problem and we are allowed 3 seconds to run, this is just within the range of possibility. The outline of the algorithm to calculate the Sprague-Grundy numbers (nimbers) is
There are a couple of optimizations one can try in case this is too slow (but naive should pass in C++): we can use the symmetry of the problem and enforce for all values computed in the DP, and then set all permutations of once we have the answer, dividing the runtime by 6. We can also change the inner loops to iterate only up to , etc, dividing the runtime by 8.