+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(ans);
	return 0;
 
}

  黑的黑白的白每一行都确定不能再改变了,如果有冲突就直接返回。

      先memset0,黑为1白为2,如果在正方形内而且有冲突直接cout<<-1 then halt;

最后统计不需要用的点,排列组合(此题迫害初中生)Cn,0+Cn,1+``````+Cn,n=2^n

那算2的n次方就得了

为什么我做那么慢?!

一开始没有读懂题目,黑白-1没考虑。

其次是键盘太烂我shift按下去弹不上来还得自己扣上来

行列hrwcij已经绕晕了。

现在我决定,为了配合debug,所有行全部放在第一个[行],列全部放在第二个。

不管坑爹题目把表格放在哪一个象限,都他妈这样处理。我换Ij换了好久。

P.S.这题好像好多人重评时都跪了,等会儿我拉个-1代码望望

猜你喜欢

转载自www.cnblogs.com/asanagiyantia/p/11612606.html
今日推荐