C - Previous Permutation Editorial by Kiri8128


As \(N\) is not very large, we can calculate the ID of \(P\) directly. If we prepare “kth_permutation” and “id_of_permutation” functions beforehand, the problem is almost trivial. Arbitrary-precision integer calculation (like in Python) would be helpful because IDs may not be very small.

AC コード (PyPy3)

posted:
last update: