QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74387 | #5442. Referee Without Red | chenshi | WA | 395ms | 60728kb | C++ | 3.2kb | 2023-01-31 23:49:30 | 2023-01-31 23:49:31 |
Judging History
answer
#include<cstdio>
#include<iostream>
using namespace std;
const int o=1e6+10,MOD=998244353;
int T,n,m,E,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 calc(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(;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);
}
int main(){
for(scanf("%d",&T);T--;printf("%d\n",ans),cnt=0){
scanf("%d%d",&n,&m);ans=inv[1]=1;E=max(n,m);
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;i<=E;++i) vis[i]=0,pri[i]=1;
for(int i=1,t,id=1;i<=cnt1;++i) 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=calc(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]=t=calc(r1[i]-l1[i]+1);
if(t&1) vis[t]=1;
else vis[t/2]=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) sam[id]=1,col[a[hsh(x,y)]]=asd,tot[v]=0;
if(!sam[id]) ans=ans*(MOD+1ll)/2%MOD;
}
n=cnt1;m=cnt2;
for(int i=2;i<=E;++i) for(int j=i*2;j<=E;j+=i) vis[i]|=vis[j],pri[j]=0;
for(int i=2;i<=E;++i) if(pri[i]) for(long long j=i;j<=E&&vis[j];j*=i) ans=ans*1ll*i%MOD;
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: 2ms
memory: 40416kb
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: 3ms
memory: 42656kb
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: 395ms
memory: 60728kb
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:
938702028 6475631 194740086 107520 40320 322560 32456681 388800 377091715 271193235 375765881 3 4 180795490 955862777 504819171 17085603 311271219 8 322560 557106771 388800 86528587 729074448 460990604 1 581172172 3 792555946 346114348 32456681 698970372 51805048 1 12 1330560 645120 847383411 394800...
result:
wrong answer 1st numbers differ - expected: '462363428', found: '938702028'