-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathb.cc
55 lines (51 loc) · 974 Bytes
/
b.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// https://codeforces.com/contest/1228/problem/B
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
const ll M = 1000000007;
ll pow(ll a, ll b, ll m) {
ll r = 1, e = a;
while (b) {
if (b & 1) (r *= e) %= m;
(e *= e) %= m;
b >>= 1;
}
return r;
}
int main() {
int h, w, r, c;
cin >> h >> w;
vvi a(h, vi(w));
for (int i = 0; i < h; ++i) {
cin >> r;
int j = 0;
for (;j < r; j++)
a[i][j] = 1;
if (j < w) a[i][j] = 2;
}
for (int i = 0; i < w; ++i) {
cin >> c;
int j = 0;
for (;j < c; j++) {
if (a[j][i] == 2) {
cout << "0\n";
return 0;
}
a[j][i] = 1;
}
if (j < h) {
if (a[j][i] == 1) {
cout << "0\n";
return 0;
}
a[j][i] = 2;
}
}
int s = 0;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
s += a[i][j] == 0;
cout << pow(2, s, M) << "\n";
}