Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define rep(i,n) for(int i=0;i<int(n);i++)
- #define rep1(i,n) for(int i=1;i<=int(n);i++)
- #define mp make_pair
- #define F first
- #define S second
- #define IOS ios_base::sync_with_stdio(0); cin.tie(0)
- #define INF 0x3f3f3f3f
- typedef long long ll;
- typedef pair<ll,ll> pii;
- typedef pair<double,double> pdd;
- const ll mod=1e9+7;
- ll n,k;
- ll h,w;
- ll r[1005],c[1005];
- ll d[1005][1005];
- ll mypow(ll a,ll b){
- ll res=1LL;
- while(b){
- if(b&1) res=res*a%mod;
- a=a*a%mod;
- b>>=1;
- }
- return res;
- }
- int main()
- {
- IOS;
- while(cin>>h>>w)
- {
- memset(r,0,sizeof(r));
- memset(c,0,sizeof(c));
- memset(d,0,sizeof(d));
- ll sum=0;
- rep1(i,h) cin>>r[i];
- rep1(i,w) cin>>c[i];
- rep1(i,h) rep1(j,r[i]) d[i][j]=1;
- rep1(j,w) rep1(i,c[j]) d[i][j]=1;
- bool flag=true;
- rep1(i,h) if(d[i][r[i]+1]==1) flag=false;
- rep1(j,w) if(d[c[j]+1][j]==1) flag=false;
- //rep1(i,h) {rep1(j,w) cout<<d[i][j]<<" ";cout<<'\n';}
- for(int i=2;i<=h;i++)
- {
- for(int j=2;j<=w;j++)
- {
- //cout<<i<<' '<<j<<' '<<c[]
- if(d[i][j]==0&&i>=c[j]+2&&j>=r[i]+2) sum++;
- }
- }
- if(!flag) cout<<"0\n";
- else cout<<mypow(2,sum)<<'\n';
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment