B. Filling the Grid codeforces

题目链接:https://codeforces.com/contest/1228/problem/B

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;
string a[1005];
const int mod = 1e9+7;
int dir[4][2] = {0,1,0,-1,1,0,-1,0};
 int main()
{
    int h,w,r[1005],c[1005],ans[1005][1005];
    while(cin >> h >> w) {
        int flag = 0;
        memset(ans,0,sizeof(ans));
        for(int i = 1; i <= h;i++) {
            cin >> r[i];
        }
        for(int i = 1; i <= w; i++) {
            cin >> c[i];
        }
        //1 代表空 2 代表满
        for(int i = 1; i <= h; i++) {
            if(r[i] == 0) {
                ans[i][1] = 1;
                continue;
            }
            for(int j = 1; j <= r[i];j++) {
                ans[i][j] = 2;
            }
            if(r[i] < w)//让最后一个满的下一个为空
                ans[i][r[i]+1] = 1;
        }
        for(int i = 1; i <= w; i++) {
            if(c[i] == 0){
                if(ans[1][i] == 2) {
                    flag = 1;
                    break;
                }
                ans[1][i] = 1;
                continue;
            }
            for(int j = 1; j <= c[i]; j++) {
                if(ans[j][i] == 1) {
                    flag = 1;
                    break;
                }
                ans[j][i] = 2;
            }
            if(flag == 1)
                break;
            if(c[i] < h)
            {
                if(ans[c[i]+1][i] == 2)
                {
                    flag = 1;
                    break;
                }
                ans[c[i]+1][i] = 1;
            }
        }
        int sum = 0;
        for(int i = 1; i <= h; i++) {
            for(int j = 1; j <= w; j++) {
                if(ans[i][j] == 0)
                    sum++;
            }
        }
        int anss = 0;
        for(int i = 0; i <= sum; i++)
            if(i == 0)
                anss = 1;
            else {
                anss*=2;
                anss %= mod;
            }
        if(flag == 1) anss = 0; //如果不满足条件break掉的 答案为0
        cout << anss << endl;
    }
    return 0;
}

 

posted on 2019-10-04 11:27  一只小毛球  阅读(188)  评论(0编辑  收藏  举报

导航