QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#736#474179#4890. 这是一道集训队胡策题GlowingfirezyxawaFailed.2024-07-13 21:16:512024-07-13 21:16:52

Details

Extra Test:

Invalid Input

input:

1 1
1

output:


result:

FAIL Expected EOLN (stdin, line 1)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#474179#4890. 这是一道集训队胡策题zyxawa100 ✓1117ms260168kbC++23873b2024-07-12 16:32:362024-07-12 16:32:37

answer

#include<bits/stdc++.h>
using namespace std;
int n,a[5001][5001],h[5001],k[5001],p[5001],q[5001];
long long ans,c[5001][5001],f[5001],g[5001];
const int mod=998244353;
void solve(int *p,int *h,long long *f){
	sort(p+1,p+1+n);
	reverse(p+1,p+1+n);
	for(int l=1,r=1;l<=n;l=r+1,r=l){
		while(r<n&&p[l]==p[r+1]) r++;
		for(int k=l;k<=r;k++) f[k]=c[r-l+1][k-l+1];
	}
	for(int i=0;i<=n;i++) for(int j=1;j<=n;j++) h[i]+=j<=i?p[j]:n-p[j];
}
int main(){
	scanf("%d",&n),f[0]=g[0]=1;
	for(int i=0;i<=n;i++) c[i][0]=1;
	for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%1d",&a[i][j]),p[i]+=a[i][j],q[j]+=a[i][j];
	solve(p,h,f),solve(q,k,g);
	for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) if(n*n==h[i]+k[j]-i*j-(n-i)*(n-j)) (ans+=f[i]*g[j])%=mod;
	printf("%lld",ans);
	return 0;
}