Seating Arrangements (hard version) solution codeforces 100% correct solution

It is the hard version of the problem. The only difference is that in this version 1≤n≤3001≤n≤300. In the cinema seats can be represented as the table with nn rows and mm columns. The rows are numbered with integers from 11 to nn. The seats in each row are numbered with consecutive integers from left to right: in the kk-th row from m(k−1)+1m(k−1)+1 to mkmk for all rows 1≤k≤n1≤k≤n. … Read more