QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#74392#5442. Referee Without RedchenshiWA 423ms61352kbC++3.5kb2023-02-01 00:27:492023-02-01 00:27:51

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-01 00:27:51]
  • 评测
  • 测评结果:WA
  • 用时:423ms
  • 内存:61352kb
  • [2023-02-01 00:27:49]
  • 提交

answer

#include<cstdio>
#include<iostream>
using namespace std;
const int o=1e6+10,MOD=998244353;
int T,n,m,a[o],b[o],p1[o],l1[o],r1[o],cnt1,p2[o],l2[o],r2[o],cnt2,ans,str[o],z[o],len1[o],len2[o],tot[o*3];
int h[o],cnt,fac[o],inv[o],col[o*3],asd;bool pri[o],vis[o],in[o],sam[o],flg;
struct Edge{int v,p;}e[o*2];
inline void ad(int U,int V){e[++cnt].v=V;e[cnt].p=h[U];h[U]=cnt;}
inline int hsh(int x,int y){return (x-1ll)*m+y;}
inline void slv(int n,int*p,int*l,int*r,int&cnt){
	cnt=0;
	for(int i=1;i<=n;i+=2) p[++cnt]=i;
	for(int i=2;i<=n;i+=2) p[++cnt]=i;
	cnt=0;
	for(int i=1;i<=n;++i) vis[i]=0;
	for(int i=1,t=0;i<=n;++i) if(!vis[i]){
		l[++cnt]=t+1;
		for(int j=i;!vis[j];j=p[j]) vis[b[++t]=j]=1;
		r[cnt]=t;
	}
	for(int i=1;i<=n;++i) p[b[i]]=i;
}
inline int exkmp(int len){
	for(int i=2,l=0,r=0;i<=len;++i){
		if(i<=r) z[i]=min(r-i+1,z[i-l+1]);
		else z[i]=0;
		for(;i+z[i]<=len&&str[z[i]+1]==str[i+z[i]];++z[i]);
		if(i+z[i]-1>r) l=i,r=i+z[i]-1;
	}
	for(int i=1;i<len;++i) if(len%i==0&&z[i+1]==len-i) return i;
	return len;
}
void dfs(int nw){
	if(col[nw]==asd) return;
	if(vis[nw]||!in[nw]){flg=1;return;}
	col[nw]=asd;
	for(int i=h[nw];i;i=e[i].p) dfs(e[i].v);
}
inline void calc(int n){
	for(int i=2;i<=n;++i) for(int j=i*2;j<=n;j+=i) vis[i]|=vis[j],pri[j]=0;
	for(int i=2;i<=n;++i) if(pri[i]) for(long long j=i;j<=n&&vis[j];j*=i) ans=ans*1ll*i%MOD;
}
int main(){
	for(scanf("%d",&T);T--;printf("%d\n",ans),cnt=0){
		scanf("%d%d",&n,&m);ans=inv[1]=1;
		slv(n,p1,l1,r1,cnt1);slv(m,p2,l2,r2,cnt2);
		for(int i=fac[0]=1;i<=n*m;++i) fac[i]=fac[i-1]*1ll*i%MOD;
		for(int i=2;i<=n*m;++i) inv[i]=MOD-MOD/i*1ll*inv[MOD%i]%MOD;
		for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) scanf("%d",&a[hsh(p1[i],p2[j])]);
		for(int i=1,t,id=1;i<=cnt1;++i){
			for(int j=1;j<=m;++j) vis[j]=0,pri[j]=1;
			for(int j=1;j<=cnt2;++j,++id)
				if(l1[i]==r1[i]){
					len1[id]=1;sam[id]=0;
					for(int k=l2[j];k<=r2[j];++k) str[k-l2[j]+1]=a[hsh(l1[i],k)];
					len2[id]=t=exkmp(r2[j]-l2[j]+1);
					if(t&1) vis[t]=1;
					else vis[t/2]=1;
				}
				else if(l2[j]==r2[j]){
					len2[id]=1;sam[id]=0;
					for(int k=l1[i];k<=r1[i];++k) str[k-l1[i]+1]=a[hsh(k,l2[j])];
					len1[id]=exkmp(r1[i]-l1[i]+1);
				}
				else{
					ans=ans*1ll*fac[(len1[id]=r1[i]-l1[i]+1)*(len2[id]=r2[j]-l2[j]+1)]%MOD;sam[id]=0;++asd;
					for(int x=l1[i],v;x<=r1[i];++x) for(int y=l2[j];y<=r2[j];ans=ans*1ll*inv[++tot[v]]%MOD,++y)
						if(col[v=a[hsh(x,y)]]^asd) col[a[hsh(x,y)]]=asd,tot[v]=0;else sam[id]=1;
					if(!sam[id]) ans=ans*(MOD+1ll)/2%MOD;
				}
			calc(m);
		}
		for(int i=1,t;i<=cnt2;++i) if(l2[i]==r2[i]){
			for(int j=1;j<=n;++j) vis[j]=0,pri[j]=1;
			for(int j=1;j<=cnt1;++j){
				for(int k=l1[j];k<=r1[j];++k) str[k-l1[j]+1]=a[hsh(k,l2[i])];
				if((t=exkmp(r1[j]-l1[j]+1))&1) vis[t]=1;
				else vis[t/2]=1;
			}
			calc(n);
		}
		n=cnt1;m=cnt2;
		for(int i=1;i<=n+m;++i) h[i]=vis[i]=in[i]=0;
		for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) if(!sam[hsh(i,j)])
			if(len1[hsh(i,j)]%2==0&&len2[hsh(i,j)]%2==0) ad(i,j+n),ad(j+n,i);
			else if(len1[hsh(i,j)]%2==0) vis[j+n]=1;
			else if(len2[hsh(i,j)]%2==0) vis[i]=1;
		if(n<m){
			for(int i=1;i<=m;++i) if(h[i+n]||vis[i+n]) in[n+i]=1,ans=ans*2%MOD;
			for(int i=1;i<=n;++i) if(h[i]||vis[i]){
				flg=0;++asd;in[i]=1;dfs(i);
				if(flg) ans=ans*2%MOD;
				else in[i]=0;
			}
		}
		else{
			for(int i=1;i<=n;++i) if(h[i]||vis[i]) in[i]=1,ans=ans*2%MOD;
			for(int i=1;i<=m;++i) if(h[i+n]||vis[i+n]){
				flg=0;++asd;in[i+n]=1;dfs(i);
				if(flg) ans=ans*2%MOD;
				else in[i+n]=0;
			}
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 40348kb

input:

2
4 4
1 2 3 4
3 4 1 2
1 2 4 1
4 3 3 2
3 9
1 8 1 1 8 1 1 8 1
1 8 8 8 8 8 8 8 1
1 1 1 8 8 8 1 1 1

output:

96
6336

result:

ok 2 number(s): "96 6336"

Test #2:

score: 0
Accepted
time: 2ms
memory: 40420kb

input:

1
18 16
8 8 1 1 8 8 8 1 8 8 8 1 8 8 8 1
8 1 8 1 8 1 1 1 8 1 1 1 8 1 1 1
8 8 8 1 8 8 8 1 8 8 8 1 8 8 8 1
8 8 1 1 8 1 1 1 8 1 1 1 8 1 1 1
8 1 8 1 8 8 8 1 8 1 1 1 8 8 8 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
8 8 1 1 8 8 8 1 8 8 8 1 7 7 7 1
8 1 8 1 8 1 1 1 8 1 1 1 1 1 7 1
8 8 8 1 8 8 8 1 8 8 8 1 1 7 7 1
8 8 ...

output:

690561281

result:

ok 1 number(s): "690561281"

Test #3:

score: -100
Wrong Answer
time: 423ms
memory: 61352kb

input:

71117
7 8
2868391 1228870 2892937 349733 664891 1675356 1981526 762573
2892937 2892937 664891 1228870 959280 762573 664891 959280
349733 250147 1675356 349733 349733 762573 1675356 250147
1675356 959280 664891 250147 250147 250147 2868391 959280
1675356 664891 250147 1228870 1981526 250147 2868391 2...

output:

462363428
38853786
194740086
215040
40320
322560
64913362
1166400
887214222
86528587
375765881
9
4
723181960
913481201
527607149
85428015
311271219
16
645120
557106771
388800
173057174
232068778
460990604
1
239327783
9
145293043
40098691
97370043
799392782
155415144
1
36
3991680
645120
545661527
558...

result:

wrong answer 7th numbers differ - expected: '32456681', found: '64913362'