QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74385 | #5442. Referee Without Red | vme50 | WA | 28ms | 75212kb | C++14 | 2.6kb | 2023-01-31 23:07:26 | 2023-01-31 23:07:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 1000005
#define M 3000005
#define LIM 10000005
#define MOD 998244353
#define pb push_back
#define gc() (P1==P2 && (P2=(P1=buf)+fread(buf,1,LIM,stdin),P1==P2)?EOF:*P1++)
char buf[LIM],*P1=buf,*P2=buf;
int T,n1,n2,m1,m2,tp1,tp2,ans,z[N],nxt[N],fa[N*2],a[M],inv[M],nw[M];
bool vs1[N],vs2[N];vector<int> vc1[N],vc2[N];
int rd()
{
int res=0;char c=0;while(!isdigit(c)) c=gc();
while(isdigit(c)) res=res*10+(c-48),c=gc();return res;
}
void init(int n)
{for(int i=1;i<=n;++i) inv[i]=i>1?1ll*inv[MOD%i]*(MOD-MOD/i)%MOD:1;}
int f(int x1,int x2) {return a[x1*n2+x2];}
int findRt(int u) {return u==fa[u]?u:fa[u]=findRt(fa[u]);}
bool merge(int u,int v)
{u=findRt(u);v=findRt(v);if(u==v) return 0;fa[u]=v;return 1;}
int slv1()
{
for(int i=2,t=0;i<=z[0];++i)
{while(t && z[i]!=z[t+1]) t=nxt[t];if(z[i]==z[t+1]) ++t;nxt[i]=t;}
for(int i=nxt[z[0]];i;i=nxt[i])
if(!(z[0]%(z[0]-i))) return z[0]-i;return z[0];
}
void slv()
{
n1=rd();n2=rd();for(int i=0;i<n1*n2;++i) {a[i]=rd();if(n1==18) putchar(a[i]+48);}
if(n1==18) putchar('\n');
m1=n1-(!(n1&1));m2=n2-(!(n2&1));ans=1;
for(int i=1;i<=tp1;++i) vc1[i].clear();
for(int i=1;i<=tp2;++i) vc2[i].clear();tp1=tp2=0;
for(int i=0;i<n1;++i) vs1[i]=0;for(int i=0;i<n2;++i) vs2[i]=0;
for(int i=1;i<m1;++i) if(!vs1[i])
{++tp1;for(int j=i;!vs1[j];j=(j*2)%m1) vs1[j]=1,vc1[tp1].pb(j);}
for(int i=1;i<m2;++i) if(!vs2[i])
{++tp2;for(int j=i;!vs2[j];j=(j*2)%m2) vs2[j]=1,vc2[tp2].pb(j);}
for(int i=1;i<=tp2;++i)
{z[0]=0;for(auto j:vc2[i]) z[++z[0]]=f(0,j);ans=1ll*ans*slv1()%MOD;}
for(int i=1;i<=tp1;++i)
{z[0]=0;for(auto j:vc1[i]) z[++z[0]]=f(j,0);ans=1ll*ans*slv1()%MOD;}
if(!(n1&1)) for(int i=1;i<=tp2;++i)
{z[0]=0;for(auto j:vc2[i]) z[++z[0]]=f(m1,j);ans=1ll*ans*slv1()%MOD;}
if(!(n2&1)) for(int i=1;i<=tp1;++i)
{z[0]=0;for(auto j:vc1[i]) z[++z[0]]=f(j,m2);ans=1ll*ans*slv1()%MOD;}
for(int i=0;i<=tp1+tp2;++i) fa[i]=i;
for(int i1=1,t,u,v,nw1;i1<=tp1;++i1) for(int i2=1;i2<=tp2;++i2)
{
bool fl=0;nw1=0;
for(auto j1:vc1[i1]) for(auto j2:vc2[i2])
{
t=f(j1,j2);++nw1;++nw[t];fl|=(nw[t]>1);
ans=1ll*ans*nw1%MOD*inv[nw[t]]%MOD;
}
if(nw1>1 && !fl)
{
u=vc1[i1].size()&1?0:tp1+i2;v=vc2[i2].size()&1?0:i1;
if(!merge(u,v)) ans=1ll*ans*inv[2]%MOD;
}for(auto j1:vc1[i1]) for(auto j2:vc2[i2]) --nw[f(j1,j2)];
}printf("%d\n",ans);
}
int main() {init(3e6);T=rd();while(T--) slv();return 0;}
詳細信息
Test #1:
score: 100
Accepted
time: 28ms
memory: 75068kb
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: -100
Wrong Answer
time: 27ms
memory: 75212kb
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:
881188818881888181818111811181118881888188818881881181118111811181818881811188811111111111111111881188818881777181818111811111718881888188811771881181118111111181818881888117111111111111111111999191919911161191119191919116119991919199911611911191919911111191119991919116111111111111111111 546340904
result:
wrong output format Expected integer, but "881188818881888181818111811181...1119991919116111111111111111111" found