B. Filling the Grid codeforces

Topic links: 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];
        }
        @Represents empty represents full 
        for ( int I = 1 ; I <= H; I ++ ) {
             IF (R & lt [I] == 0 ) { 
                ANS [I] [ 1 ] = 1 ;
                 Continue ; 
            } 
            for ( int J = . 1 ; J <= R & lt [I]; J ++ ) { 
                ANS [I] [J] = 2 ; 
            } 
            IF (R & lt [I] <W) // make the last full next empty 
                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 ;
             the else { 
                ANSS * = 2 ; 
                ANSS % = MOD; 
            } 
        IF (In Flag == . 1 ) ANSS = 0 ; // if the condition break out the answer to 0 
        COUT << << ANSS endl; 
    } 
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/LLLAIH/p/11621722.html