문제
Note: The time limit for this problem is 4s, twice the default.
Moo! You are given an integer (). Consider all permutations of . Let denote the minimum absolute difference between any two consecutive elements of . and let denote the set of all that achieve the maximum possible value of .
You are additionally given () constraints of the form (). Count the number of permutations in satisfying all constraints, modulo .
입력
The first line contains () and , meaning that you will need to solve independent test cases, each specified by a different set of constraints.
Each test case starts with , followed by lines each containing and . It is guaranteed that The same does not appear more than once within the same test case.The same does not appear more than once within the same test case.
출력
For each test case, the answer modulo on a separate line.
예제 입력 1
3 4
0
1
1 1
2
0 2
2 3
예제 출력 1
2
0
1
예제 입력 2
9 11
2
0 5
6 9
3
0 5
6 9
1 0
4
0 5
6 9
1 0
4 7
5
0 5
6 9
1 0
4 7
2 6
6
0 5
6 9
1 0
4 7
2 6
9 3
7
0 5
6 9
1 0
4 7
2 6
9 3
5 2
8
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
9
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
3 1
10
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
3 1
8 10
예제 출력 2
6
6
1
1
1
1
1
1
1
예제 입력 3
10 11
0
1
3 8
2
3 8
5 7
3
3 8
5 7
4 2
4
3 8
5 7
4 2
10 6
5
3 8
5 7
4 2
10 6
8 10
6
3 8
5 7
4 2
10 6
8 10
1 9
7
3 8
5 7
4 2
10 6
8 10
1 9
7 5
8
3 8
5 7
4 2
10 6
8 10
1 9
7 5
2 3
9
3 8
5 7
4 2
10 6
8 10
1 9
7 5
2 3
6 0
예제 출력 3
160
20
8
7
2
1
1
1
1
1
예제 입력 4
5 987
3
654 321
543 210
432 106
2
654 321
543 210
1
654 321
1
0 493
0
예제 출력 4
0
538184948
693625420
932738155
251798971
점수
Input 5: Input 6: Inputs 7-9: For all test cases, the constraint appears.Inputs 10-13: For all test cases, there exists some constraint with equal to .Inputs 14-20: No additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인