Practice Contest I Problem D Life Game Original
Practice Contest I Problem D : Life Game Original Problem : H. Noda Solution : H. Noda and K. Inaba Presentation : H. Noda
Problem (1) • Simulate self-propagation of virus – “The virus has a tendency to build up regular hexagonal colonies. So as a whole, the virus weapon forms a hexagonal grid, each hexagon being a colony of the virus. ” – “The virus self-propagates at a constant period speed. Selfpropagation is performed simultaneously at all colonies. When it is done, for each colony, the same number of viruses are born at every neighboring colony. ” – Note that, after the self-propagation, if the number of viruses in one colony is more than or equal to the limit density $M$, then the viruses in the coloy start selfattacking, and the number reduces modulo $M$.
Problem (2) • 1<=N<=6 1<=M<=109 1<=L<=109
Solution (1) 1. Create a row vector which denotes elements of given hexagonal grid 2. Create a matrix which denotes grid adjacency 3. Multiply the matrix by itself for L times 4. Multiply the vector by the matrix 5. Add each element of the vector
Solution (2) • Create a row vector which denotes elements of given hexagonal grid [0 1 2 3 4 5 6]
Solution (3) • Create a matrix which denotes grid adjacency 1 1 0 0 0 1 1 0 0 1 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1
Solution (4) 1 1 1 [0 1 2 3 4 5 6] 1 0 0 0 1 1 0 0 1 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1 • This expression produce a row vector – The row vector denotes the elements of grid after one self-propagation
Solution (5) 1 1 1 [0 1 2 3 4 5 6] 1 0 0 0 1 1 0 0 1 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1 L • This expression produce a row vector – The row vector denotes the elements of grid after L self-propagations
Solution (6) • Power of matrix can be calculated in O(log(L)) matrix mm[64]; mm[0] = adj; for (int i = 1; i < 32; ++i){ mm[i] = multiply(mm[i - 1], mm[i - 1]); } matrix m; identify(m, nn); for (int i = 0; i < 32; ++i){ if (l & (1 LL << (ll)i)){ m = multiply(m, mm[i]); } }
Warning • Each element of grid does not exceed 109 • But sum of whole elements exceeds 109 – Use “long” for results
Judges’ Solutions • Noda’s solution – 158 lines – C++ • Inaba’s solution – 111 lines – Java
Submission • • Number of submission : 9 Number of accepted : 5 First submission : ____ (43 min) WA First accepted : ____ (72 min)
Thank you for listening
- Slides: 13