+Codeforces Round #589 (Div. 2) B Filling the Grid

#include <bits/stdc++.h>
using namespace std;
int g[1001][1001], c[1001], r[1001]; //g[r][c]
int h, w, ans;
 
long long work(int ans)
{
	long long p=1;
	for (int q=1;q<=ans;q++)
	{
		p = (p * 2) % (1000000007);
	}
	return p;
}
 
int main()
{
	memset(g, 0, sizeof(g));
	cin >> h >> w;
	for (int i = 1; i <= h; i++)
	{
		cin >> r[i];
		for (int j = 1; j <= r[i]; j++)
		{
			if (g[i][j] == 2)
			{
				cout << 0;
				return 0;
			}
			g[i][j] = 1;
		}
		if (r[i] < w && g[i][r[i] + 1] == 1)
		{
			cout << 0;
			return 0;
		}
		g[i][r[i] + 1] = 2;
		 
	}
	for (int i = 1; i <= w; i++)
	{
		cin >> c[i];
		for (int j = 1; j <= c[i]; j++)
		{
			if (g[j][i] == 2)
			{
				cout << 0;
				return 0;
			}
			g[j][i] = 1;
		}
 
		if (c[i] < h && g[c[i] + 1][i] == 1)
		{
			cout << 0;
			return 0;
		}
		g[c[i] + 1][i] = 2;
	}
 
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			if (g[i][j]==0) ans++;
	cout << work (years);
	return 0;
 
}

  Black white black and white Each row can not be changed determine if there is a direct conflict to return.

      First memset0, black and white is 2 to 1, and if there is a conflict in the square directly cout << - 1 then halt;

Finally, statistics do not need points, permutations (this question persecution junior high school students) Cn, 0 + Cn, 1 + `` `` `` + Cn, n = 2 ^ n

That operator would have a 2 ^ n

 

Why do I so slow? !

Not initially understand the topic, not black and white -1 consideration.

Followed by the keyboard sucks my shift shells do not press down to buckle up have their own

Hrwcij already ranks around dizzy.

Now I have decided, in line with debug, all rows in all on the first [line], all on the second row.

Regardless of pit father entitled to a table on which quadrant, I am his mother so treated. I changed Ij for a long time.

PS This question seems to have a lot of people comment when heavy kneeling, wait a minute I looked at the code pull a -1

Guess you like

Origin www.cnblogs.com/asanagiyantia/p/11612606.html