跳到正文

题解

CF2240B AI Finds Nothing Here

shiziyu111约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年6月28日
收录
2026年11月24日
更新
2026年11月24日
篇幅
约 2 分钟
获赞
7
题目
CF2240B

版本

  1. v1当前

考虑固定一些数,以推出所有的数。

首先我们知道,假如我们确定了一个矩形除去一个格子意外的所有格子,那么我们也能知道这个格子长啥样。

因此我们先固定左上角 (r×c)−1(r\times c)-1 个格子,如下(r=3,c=3,n=4,m=6r=3,c=3,n=4,m=6):

考虑扩展,我们发现假如将右边的 (r−1)(r-1) 个格子固定,那么格子 (c+1,r)(c+1,r) 也是确定的,此时固定的格子如下:

一直固定下去,最后的结果如下:

此时我们欣喜的发现,我们可以像推数独一样通过不断左右或上下移动矩形来确定新的点,最后就能推出整张矩形的面貌,也就是说,我们无需再固定新的点了。

最后数一下有多少个点亟待固定,有 n×m−(n−r+1)×(m−c+1)n\times m-(n-r+1)\times(m-c+1) 个点,每个点选择两种颜色,答案为 2n×m−(n−r+1)×(m−c+1)2^{n\times m-(n-r+1)\times(m-c+1)}(说实话我看到这个答案气笑了)。

Code

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353;
int qpow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1; 
	}
	return res;
}
void solve()
{
	int n,m,r,c;
	scanf("%lld%lld%lld%lld",&n,&m,&r,&c);
	printf("%lld\n",qpow(2,n*m-(n-r+1)*(m-c+1)));
}
signed main()
{
	int T;
	scanf("%lld",&T);
	while(T--)
	{
		solve();
	}
	return 0;
}
原文