QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#298#75559#4890. 这是一道集训队胡策题4182_543_7314182_543_731Success!2023-02-05 20:23:072023-02-05 20:23:09

Details

Extra Test:

Wrong Answer
time: 0ms
memory: 5736kb

input:

8
10000000
01000000
11100000
11010000
11111000
11110100
11111010
11111111

output:

4

result:

wrong answer 1st numbers differ - expected: '6', found: '4'

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#75559#4890. 这是一道集训队胡策题4182_543_73197 324ms51300kbC++1.5kb2023-02-05 20:22:362023-02-05 20:24:22

answer

#include<cstdio>
#include<algorithm>
using namespace std;
#define N 5050
#define mod 998244353
int n,ct[N],id[N],p2[N];
char s[N][N],t[N][N];
bool cmp(int a,int b){return ct[a]<ct[b];}
int l1x[N],r0x[N],l1y[N],r0y[N];
int solve(int lx,int rx,int ly,int ry)
{
	if(lx>rx)return p2[ry-ly+1];
	if(ly>ry)return p2[rx-lx+1];
	if(l1x[lx]>ry)
	{
		int tp=lx;while(tp<=rx&&l1x[tp]>ry)tp++;
		return (p2[tp-lx]-1+solve(tp,rx,ly,ry))%mod;
	}
	if(r0x[rx]<ly)
	{
		int tp=rx;while(tp>=lx&&r0x[tp]<ly)tp--;
		return (p2[rx-tp]-1+solve(lx,tp,ly,ry))%mod;
	}
	if(l1y[ly]>rx)
	{
		int tp=ly;while(tp<=ry&&l1y[tp]>rx)tp++;
		return (p2[tp-ly]-1+solve(lx,rx,tp,ry))%mod;
	}
	if(r0y[ry]<lx)
	{
		int tp=ry;while(tp>=ly&&r0y[tp]<lx)tp--;
		return (p2[ry-tp]-1+solve(lx,rx,ly,tp))%mod;
	}
//这好像都行.jpg
return 2;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	{
		ct[i]=0;id[i]=i;
		for(int j=1;j<=n;j++)ct[i]+=s[i][j]=='1';
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)t[i][j]=s[id[i]][j];
	for(int i=1;i<=n;i++)
	{
		ct[i]=0;id[i]=i;
		for(int j=1;j<=n;j++)ct[i]+=t[j][i]=='1';
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)s[i][j]=t[i][id[j]];
	for(int i=1;i<=n;i++)l1x[i]=l1y[i]=n+1;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(s[i][j]=='0')r0x[i]=j,r0y[j]=i;
	for(int i=n;i>=1;i--)for(int j=n;j>=1;j--)if(s[i][j]=='1')l1x[i]=j,l1y[j]=i;
	p2[0]=1;for(int i=1;i<=n;i++)p2[i]=2*p2[i-1]%mod;
	printf("%d\n",solve(1,n,1,n));
}