公式

D - Distinct Sum Grid Path 解説 by evima


When \(N=13\), the number of paths is \(\binom{24}{12}-1 = 2704155\), leaving only about two times margin for \(6 \times 10^6\).

In fact, it is possible to tightly construct scores from \(0 \dots \binom{2N-2}{N-1}-1\).

Adding one row at a time, each row can be filled from right to left as follows:

0  0  0  0  0  0
1  1  1  1  1  0
2  3  4  5  5  0
4  7 11 15 15  0
 ... 25 35 35  0

Specifically, write so that for paths from \((1,1)\) to \((i,N)\), the score matches the lexicographic order (0-indexed) of the sequence obtained by reversing the sequence where down moves are 0 and right moves are 1. You can implement it using the fact that the set of scores for paths from \((1,1)\) to \((i,j)\) is a set of consecutive integers.

Source code


Intended wrong approach

A construction like:

 0  0  0  0  0
 1  2  4  8 16
 0  0  0  0  0
 4  8 16 32 64
 0  0  0  0  0

where the branching at the \(i\)-th step corresponds to \(2^i\), results in a max score of \(2^{23}-1=8388607\), which exceeds the limit. The writer has not come up with a way to improve the max score while keeping this approach.

投稿日時:
最終更新: