Submission #6953688


Source Code Expand

Copy
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
MOD = 10 ** 9 + 7

MN = M * N
A_gt = [0] * MN
B_gt = [0] * MN
ans = 1
for Ai in A:
    if A_gt[Ai - 1] > 0:
        ans = 0
        break
    A_gt[Ai - 1] = 1
for Bi in B:
    if B_gt[Bi - 1] > 0:
        ans = 0
        break
    B_gt[Bi - 1] = 1

if ans != 0:
    for i in range(MN - 2, -1, -1):
        A_gt[i] += A_gt[i + 1]
        B_gt[i] += B_gt[i + 1]
    ans = A_gt[MN - 1] * B_gt[MN - 1]
    for i in range(MN - 2, -1, -1):
        is_max_in_A = A_gt[i] != A_gt[i + 1]
        is_max_in_B = B_gt[i] != B_gt[i + 1]
        if is_max_in_A and is_max_in_B:
            ans *= 1
        elif is_max_in_A:
            ans *= B_gt[i]
        elif is_max_in_B:
            ans *= A_gt[i]
        else:
            ans *= A_gt[i] * B_gt[i] - (MN - 1 - i)
        ans %= MOD
print(ans)

Submission Info

Submission Time
Task D - Double Landscape
User toshikish
Language Python3 (3.4.3)
Score 500
Code Size 930 Byte
Status
Exec Time 1338 ms
Memory 82164 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt, s4.txt
All 500 / 500 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt 1032 ms 72336 KB
02.txt 1087 ms 70692 KB
03.txt 1083 ms 75508 KB
04.txt 1008 ms 72180 KB
05.txt 1200 ms 79668 KB
06.txt 994 ms 69876 KB
07.txt 1130 ms 77428 KB
08.txt 1046 ms 77044 KB
09.txt 1068 ms 74612 KB
10.txt 1051 ms 74484 KB
11.txt 1071 ms 68796 KB
12.txt 1152 ms 74864 KB
13.txt 1094 ms 73852 KB
14.txt 970 ms 69176 KB
15.txt 1065 ms 72968 KB
16.txt 1045 ms 74228 KB
17.txt 1082 ms 75636 KB
18.txt 1297 ms 81312 KB
19.txt 1285 ms 81816 KB
20.txt 1297 ms 81816 KB
21.txt 1275 ms 81524 KB
22.txt 1219 ms 82164 KB
23.txt 1338 ms 81440 KB
24.txt 1220 ms 81140 KB
25.txt 1332 ms 81184 KB
26.txt 1212 ms 81140 KB
27.txt 1257 ms 81440 KB
28.txt 1172 ms 81184 KB
29.txt 1283 ms 81268 KB
30.txt 1246 ms 81268 KB
s1.txt 17 ms 3064 KB
s2.txt 17 ms 3064 KB
s3.txt 17 ms 3064 KB
s4.txt 17 ms 3064 KB