Submission #6952885


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]
    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 0
Code Size 891 Byte
Status
Exec Time 1275 ms
Memory 83316 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt, s4.txt
All 0 / 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 1021 ms 72336 KB
02.txt 1106 ms 70692 KB
03.txt 1105 ms 75508 KB
04.txt 1068 ms 72180 KB
05.txt 1209 ms 79668 KB
06.txt 1060 ms 69876 KB
07.txt 1159 ms 77428 KB
08.txt 1046 ms 74996 KB
09.txt 1095 ms 74612 KB
10.txt 1084 ms 74484 KB
11.txt 1039 ms 70844 KB
12.txt 1177 ms 74740 KB
13.txt 1150 ms 73852 KB
14.txt 1015 ms 69176 KB
15.txt 1090 ms 73096 KB
16.txt 1052 ms 74228 KB
17.txt 1204 ms 75636 KB
18.txt 1263 ms 81312 KB
19.txt 1240 ms 81816 KB
20.txt 1258 ms 81816 KB
21.txt 1247 ms 81524 KB
22.txt 1262 ms 82164 KB
23.txt 1221 ms 81440 KB
24.txt 1220 ms 81140 KB
25.txt 1235 ms 81188 KB
26.txt 1212 ms 81140 KB
27.txt 1225 ms 81440 KB
28.txt 1271 ms 81188 KB
29.txt 1203 ms 83316 KB
30.txt 1275 ms 81268 KB
s1.txt 19 ms 3064 KB
s2.txt 19 ms 3064 KB
s3.txt 19 ms 3064 KB
s4.txt 20 ms 3064 KB