Lost Table
Time limit2sMemory limit2048 MB
Count the n by m tables of positive integers whose row maxima are a and column maxima are b, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math, Sorting
- Solved
- No attempts yet
Problem
Er-Tostik had a table of size filled with positive integers. Aldar-Kose stole the table as a prank and told Er-Tostik only the maximum value of each row and each column. Aldar-Kose will return the table only if Er-Tostik can count how many different tables have these row and column maxima. The count can be very large, so output it modulo . Help Er-Tostik get his table back.
Input
The first line contains two integers and (), the dimensions of the table. The second line contains integers (), the maximum values of the rows. The third line contains integers (), the maximum values of the columns.
Output
Print one integer: the number of tables that satisfy the conditions, modulo . If no table matches the given maxima, print 0.