Complexity of permutation problem

Revision en2, by yoshi_likes_e5, 2025-03-05 04:18:59

There is a problem that I solved earlier: Find how many permutations p s.t. $$$|p_i-i|\leq k$$$ for all $$$i$$$. Constraints: $$$n\leq 10^9,k\leq 4$$$. I solved it using matrix multiplication (converted ARC132C 's transitions to matrix form), but naively multiplying the matrix creates the insane complexity of $$$O(64^k*\log(n))$$$. By skipping the non-zero terms in the left hand side, I was able to get it passed. Can anyone explain why this passes, and maybe prove the complexity of it?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English yoshi_likes_e5 2025-03-05 04:18:59 117 Tiny change: '/arc132_c)'s transit' -> '/arc132_c) 's transit'
en1 English yoshi_likes_e5 2025-03-05 04:17:42 451 Initial revision (published)